I’ve added a history table to my database. Originally I added a Bit called Deleted and intended to update it to 1 if that row was ever deleted, otherwise each row is an update.
Then I was informed we need to log who deleted what when. So I added Nullable [DeletedBy] [DeletedOn] fields.
At this point I was wondering if this made my Deleted Bit redundant. You could simply query the table, checking where DeletedBy is not Null if you want to see which row is Deleted.
I intended to ask in this question which is better practice:
-
Having the extra Bit Column
-
Using the nullable columns that are already there, to Identify Deleted Rows
But I’m starting to think this is a preference thing. So instead my question is, which is more efficient? If this table gets massive, is there a performance gain to running:
Select * from MyTable where [Deleted] = 1
over
Select * from MyTable where [DeletedBy] is not null
This is more a preference. Technically the
datetimefield is larger than abitfield, but since you are required to store it anyway it does not really matter. However performance wise you can index either and get the same results. I personally think thebitfield is redundant and use the nullabledatetime.