A unique constraint can be extended over multiple columns : Unique « Constraints « Oracle PL / SQL






A unique constraint can be extended over multiple columns

  


SQL> -- A unique constraint can be extended over multiple columns:
SQL>
SQL> create table myTable (
  2    a number,
  3    b number,
  4    c number,
  5    unique (a,b)
  6  );

Table created.

SQL>
SQL> insert into myTable values (4, 3,  5);

1 row created.

SQL> insert into myTable values (4, 1,  5);

1 row created.

SQL> insert into myTable values (4, 2,  5);

1 row created.

SQL> insert into myTable values (4, 3,  5);
insert into myTable values (4, 3,  5)
*
ERROR at line 1:
ORA-00001: unique constraint (SYS.SYS_C004360) violated


SQL>
SQL> select * from myTable;

         A          B          C
---------- ---------- ----------
         4          3          5
         4          1          5
         4          2          5

SQL>
SQL> drop table myTable;

Table dropped.

SQL>
SQL>
           
         
    
  








Related examples in the same category

1.if a column is not explicitely defined as not null, nulls can be inserted multiple times
2.Vialate the unique contraint: try to insert the same value
3.Add unique containt to a varchar2 type column
4.Create a table with 'unique deferrable initially immediate'
5.Add unique constraints
6.ORA-00001: unique constraint (JAVA2S.JOB_UNIQUE_IN_TEAMID) violated
7.Setting a Unique Constraint
8.Unique value column