I need a check constraint on two columns, at least one must be not null

前端 未结 2 1431
甜味超标
甜味超标 2021-02-18 20:18

I have a table in SQL Server with two numeric columns. At least one of these numeric fields must be filled. How do I write a check constraint to verify this?

2条回答
  •  走了就别回头了
    2021-02-18 20:58

    late answer, but here is a solution for Sql Server for any number of columns to check:

    CONSTRAINT CK_one_is_not_null CHECK (COALESCE(col1, col2, col3) IS NOT NULL )
    

提交回复
热议问题