What to do when I want to use database constraints but only mark as deleted instead of deleting?

后端 未结 10 1005
野的像风
野的像风 2020-12-31 20:55

I am working in a project where database items are not deleted, but only marked as deleted. Something like this:

id   name     deleted
---  -------  --------         


        
10条回答
  •  -上瘾入骨i
    2020-12-31 21:38

    For a simple table called [Test] with columns ID(int), Filter(nvarchar), Deleted(bit)

    ALTER TABLE [dbo].[Test] ADD 
        CONSTRAINT [DF_Test_Deleted] DEFAULT (0) FOR [Deleted],
        CONSTRAINT [IX_Test] UNIQUE  NONCLUSTERED 
        (
            [filter],
            [Deleted]
        )  ON [PRIMARY] 
    

提交回复
热议问题