开发者

How to set minimum value for a SQL Server column

开发者 https://www.devze.com 2023-02-28 04:13 出处:网络
I am using SQL Server 2008 R2 I want to set a column minimum value Column type is int I want to set minimum value of 0

I am using SQL Server 2008 R2

I want to set a column minimum value

Column type is int

I want to set minimum value of 0

So开发者_运维技巧 if I update the column with -32 it should automatically set column value to 0


The simplest solution is to force the calling code to correct their data rather than magically alter it on insert. To do that, add a check constraint:

Alter Table MyTable
    Add Constraint CK_MyTable_Col Check ( MyCol >= 0 )


Use Check Contraints ..

0

精彩评论

暂无评论...
验证码 换一张
取 消