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>
|