Search

PRIMARY KEY




Ø  This is used to avoid duplicates and nulls. This will work as combination of unique and not null.
Ø  Primary key always attached to the parent table.
Ø  We can add this constraint in all three levels.

Ex:
      COLUMN LEVEL

      SQL> create table student12(no number(2) primary key, name varchar(10), marks
             number(3));
      SQL> create table student12(no number(2)  constraint pk primary key, name varchar(10),
             marks number(3));
     


      TABLE LEVEL

      SQL> create table student12(no number(2) , name varchar(10), marks number(3),
             primary key(no));
      SQL> create table student12(no number(2) , name varchar(10), marks number(3),
             constraint pk primary key(no));

      ALTER LEVEL

      SQL> alter table student12 add primary key(no);
      SQL> alter table student12 add constraint pk primary key(no);