Primary keys can explicitely be named : Name for Primary Key « Constraints « Oracle PL / SQL






Primary keys can explicitely be named


SQL> -- Primary keys can explicitely be named.
SQL> -- create table statement creates a table with a primary key whose name is pk_name.
SQL>
SQL> create table myTable (
  2    a number,
  3    b number,
  4    c number,
  5    constraint pk_name primary key (a, b)
  6  );

Table created.

SQL>
SQL>
SQL> insert into myTable values (1,2,3);

1 row created.

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

1 row created.

SQL> insert into myTable values (1,3,3);

1 row created.

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

1 row created.

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


SQL>
SQL> select * from myTable;

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

SQL>
SQL> drop table myTable;

Table dropped.

SQL>
SQL>

           
       








Related examples in the same category