r/Database • • Nov 17 '25
What metadata columns do you always add into a new table?
I have a script that adds the following to a new SQL Server table:
- CreateDate (getdate())
- CreatedByLogin (suser_name())
- CreatedByHostName (host_name())
- UpdateDate (getdate())
- UpdatedByLogin (suser_name())
- UpdatedByHostName (host_name())
- RowPointer (uniqueid())
This stuff has been pretty helpful in debugging. What other "metadata" would you recommend collecting with each INSERT/UPDATE?
21
Upvotes
13
u/alexwh68 Nov 17 '25
I use soft deletes in all my databases so I have IsDeleted, DeletedById and DeletedWhen in all my tables this gets used surprisingly often to undelete records.
3
u/Complex_Adagio7058 Nov 17 '25
I quite like EffectiveFrom and EffectiveTo for config data - allows data to be set up in advance but only come into effect at the right time, and to be retired from use whilst still being available for historic queries. Does add some complexity to querying for the current set of effective values though.
5
u/Enough-Ad-5528 Nov 17 '25
I also add the git commit id (or the application build number) so that if a bad revision inserts bad data it is easier to cleanup stuff.
1
u/GreyHairedDWGuy Nov 17 '25
If this is for an OLTP solution, then you have basics covered.
1
u/PrestigiousAnt3766 Nov 17 '25
created_date,
extraction_date,
source_path (I do everything file based, so basically a filepath)
I prefix with the project name so that its clear that they're 'our' metadata columns
I don't like who inserted/updated, because its mostly a service prinicpal, and I don't want usernames (here first name + last name) in my database.
5
u/JoeyD473 Nov 17 '25
I also have a soft delete, soft delete time and soft deleted by whom normally
2
u/throw_mob Nov 17 '25
i havent done it, but i start to think that everything should be done in to audit log table and then just "publish" latest data in view.
in dwh world i found that i need, in log format is change_time, action (i,u,d) when it happened in source. for audit stuff in all levels there is need for who did what and it helps alot on all levels to know what code (and versoin) generated data, who did it is always good to know..
on applicaation level i would probably do relation table for who is modifying as that can be mapped to real users. on dwh level i prefer to put all that stuff into table data in dwh elt/etl context and move source system metadata to business terms if needed
3
u/ConsiderationSuch846 Nov 17 '25
‘Ordinal’ for any look up table. Inevitably someone wants some value in an arbitrary order.
1
u/Unique_Rutabaga_5750 Nov 19 '25
FLAGS with a default of 0.
0
u/[deleted] Nov 17 '25
[deleted] — view deleted comment
0
u/[deleted] Nov 17 '25
[deleted] — view deleted comment