sql server add column with default value

alter table AdventureWorks2019.sales.SalesOrderDetail
add   IsValid bit not null
constraint IsValid_Default_Constraint Default 1
with values;

This will make a sense when you want to delete logically instead of delete physically.

For example physically deletion.

delete from tableName where id=conditionValue;

While the logically deletion will be more elegant and easy to roll back or restore/undo.

update tableName set IsValid=0 where id=conditionValue

and when you retrieve valid result just add where condition to filter as below

select * from tableName where IsValid=1;

posted @ 2020-12-03 22:18  FredGrit  阅读(273)  评论(0编辑  收藏  举报