开发者

SQL Server NULL constraint

Is is possible in SQL Server 2008 to create such a constraint that would restrict two columns to have NULL values at the same time? So that

Column1 Column2
NULL    NULL   -- not 开发者_如何学Goallowed
1       NULL   -- allowed
NULL    2      -- allowed
2       3      -- allowed


ALTER TABLE MyTable WITH CHECK 
   ADD CONSTRAINT CK_MyTable_ColumNulls CHECK (Column1 IS NOT NULL OR Column2 IS NOT NULL)

As part of the create

CREATE TABLE MyTable (
 Column1 int NULL,
 Column2 int NULL,

 CONSTRAINT CK_MyTable_ColumNulls CHECK (Column1 IS NOT NULL OR Column2 IS NOT NULL)
)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜