Primary Key
- It is a entity integrity.
- It ignore Null values.
- It ignore duplicates.
- only one primary key accepted in a table.
- It automatically create unique index.
Primary Key = Unique Key + Not Null
Scenario :
consider one table name as course and column are course table is CId and CName. Here set cid is primary key.
Syntax :
create table course123( CId Number, CName varchar(2) constraints c1 primary key(CId)) ;
Table Created;
insert into course123 values(1,'parthi');
insert into course123 values(2,'karthi');
Two Rows Inserted
insert into course123 values(1,'prakash');
when inserting this third row face this error
ORA-00001: unique constraint (HR.C1) violated
Note: Here Cid value is 1 Its already inserted). The main thing in the primary key constraints is ignores null values and duplicates.
No comments:
Post a Comment