One of the column between two columns should be NOT NULL. How to enforce it in schema?

后端 未结 1 619
花落未央
花落未央 2020-12-10 10:49

I have a table with following scehma

CREATE TABLE MyTable  
(  
    ID                INTEGER DEFAULT(1,1),      
    FirstIdentifier   INTEGER NULL,    
            


        
相关标签:
1条回答
  • 2020-12-10 11:50

    This is possible with using a CHECK constraint:

    CHECK (FirstIdentifier IS NOT NULL OR SecondIdentifier IS NOT NULL)
    

    While CHECK constraints are part of the table (and hence "schema"?), they may not fit the desired definition. The above CHECK is not mutually exclusive, but it could be altered to such.

    Happy coding.

    0 讨论(0)
提交回复
热议问题