Unique Key
- Its a entity and integrity.
- It ignores duplicates.
- It accept null values and multiple null values.
- Its automatically generates unique as index.
Scenario :
consider one table name as course234 and column are course table is CId and CName. Here set cid is unique key.
Syntax :
create table course( CId Number, CName varchar(2) constraints c2 unique(CId)) ;
Table Created;
insert into course234 values(1,'parthi');
insert into course234 values(2,'karthi');
Two Rows Inserted
insert into course234 values(1,'prakash');
when inserting this third row face this error
ORA-00001: unique constraint (HR.C1) violated
insert into course234 values(null ,'prakash');
1 row inserted
Note: Here Cid value is 1 Its already inserted. The main thing in the unique constraints is ignores duplicate values but it accept null values.
select * from course234;
Output :
CID CNAME
1 parthi
2 karthi
- prakash
No comments:
Post a Comment