sql unique constraint on a 2 columns combination

前端 未结 3 684
梦毁少年i
梦毁少年i 2020-12-03 23:41

How can you create a unique constraint on a combination of two values in two columns.

meaning

column1  column2 
   2        1 

lo

3条回答
  •  再見小時候
    2020-12-04 00:30

    Looking at the documentation, found this for the ORACLE SGBD :

    CREATE TABLE b(
     b1 INT, 
     b2 INT, 
     CONSTRAINT bu1 UNIQUE (b1, b2) 
                    USING INDEX (create unique index bi on b(b1, b2)),
     CONSTRAINT bu2 UNIQUE (b2, b1) USING INDEX bi);
    

    Chapter "Specifying the Index Associated with a Constraint" on the page ORACLE documentation.

    Hop this help.

提交回复
热议问题