Name the constraint
SQL> --name the constraint.
SQL> -- creates a unique constraint on the columns a and b and names the constraint uq_myTable.
SQL>
SQL> create table myTable (
2 a number,
3 b number,
4 c number,
5 constraint uq_myTable unique (a,b)
6 );
Table created.
SQL>
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.UQ_MYTABLE) 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