Primary Key

Primary Key 


Primary Key :- Primary key is a combination of NOT NULL and UNIQUE Key Constraint, Primary key never allow duplicate values and null values in the column.


1) Primary Key (Column Level) :-

a) With System defined name


SQL>create table student(regno number(10) primary key, name varchar2(10),dob date, course varchar2(10));


b) With User defined name


SQL>create table student(regno number(10) constraint pk_regno primary key,name varchar2(10),dob date,course varchar2(10));


2) Primary Key (Table Level) :-


a) With System defined name


SQL>create table student(regno number(10),name varchar2(10),dob date,course varchar2(10), primary key(regno));


b) With User defined name


SQL>create table student(regno number(10),name varchar2(10),dob date,course varchar2(10),constraint pk_regno primary key(regno));


3) Composite Primary Key :- Key, that is created for more that one column is called composite key. If Primary Key is created for more than one column then that Primary Key is called Composite Primary Key.


a) With System defined name


SQL>create table student(regno number(10),name varchar2(10),dob date,course varchar2(10), primary key(regno,name));


b) With User defined name


SQL>create table student(regno number(10),name varchar2(10),dob date,course varchar2(10),constraint pk_regno primary key(regno,name));

                  



--------------------------HAPPY LEARNING -----------------------------


                                                                                                   **THANK YOU**

No comments:

Post a Comment