Primary Key: A primary key combines a unique and a not null constraint : Primary Key « Constraints « Oracle PL / SQL






Primary Key: A primary key combines a unique and a not null constraint



SQL> --Primary Key: A primary key combines a unique and a not null constraint.
SQL>
SQL> -- Additionally, a table can have at most one primary key. After creating a primary key, it can be referenced by a foreign key.
SQL>
SQL> create table myTable (
  2    a number primary key,
  3    b number
  4  );

Table created.

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

1 row created.

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

1 row created.

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

1 row created.

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


SQL>
SQL> select * from myTable;

         A          B
---------- ----------
         1          2
         2          2
         3          2

SQL>
SQL> drop table myTable
  2
SQL> /

Table dropped.

SQL>
           
       








Related examples in the same category

1.Create a primary key with more than one field
2.Alter to add primary key
3.DISTINCT keyword with primary key in select clause