Click here to Skip to main content
15,041,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to create a field for deleted records in SQL but as the field is newly implemented what should be the state for already exisitng records? As the column is a boolean field.

What I have tried:

Created a column in DB as a boolean field,but for the existing fileds does the value should be null or 0?
Posted
Updated 1-Jul-21 21:47pm
Comments
PIEBALDconsult 2-Jul-21 9:44am
   
Rather than a boolean value, consider a datetime which is NULL for current records and the timestamp of deletion for deleted records, it's a much more informative.
Maciej Los 5-Jul-21 4:19am
   
This sounds like an answer!

1 solution

When you create the field, you can set a DEFAULT value: SQL DEFAULT Constraint[^]

But, for a boolean field what value it should have is use specific: for a BIT field 0 is false and 1 is true - but your application will determine which way existing records should be set. If it's a "deleted" indicator, then if all existing / new rows should be considered "undeleted" then you'll want false for example.
We dont; know how you plan to use this, so we can't tell you "do this"!
   
Comments
chandra sekhar 2-Jul-21 5:35am
   
Correct, but what is the best option to insert for already existing records? I have a driver table where i am inserting the deleted column with (bit,null) but for the existing drivers what should be the correct way to show the value a null or 0 and in which scenario null is inserted?
OriginalGriff 2-Jul-21 6:00am
   
How would I know which you need: 0 or 1?
Read what I said, please!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900