Unique Constraint::
================
-Restricted Duplicates values but accepting nulls into a column
column level::
============
>create table test1(sno int unique,name varchar2(10) unique);
EX::
SQL> create table test1(eid int unique,ename varchar2(10) unique);
Table created.
SQL> insert into test1 values(10,'virat');
1 row created.
SQL> select * from test1;
EID ENAME
---------- ----------
10 virat
SQL> insert into test1 values(10,'rohit');
insert into test1 values(10,'rohit')
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C007643) violated
SQL> insert into test1 values(20,'virat');
insert into test1 values(20,'virat')
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C007644) violated
SQL> insert into test1 values(20,'rohit');
1 row created.
SQL> select * from test1;
EID ENAME
---------- ----------
10 virat
20 rohit
SQL> insert into test1(null,'raja');
insert into test1(null,'raja')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword
SQL> insert into test1 values(null,'raja');
1 row created.
SQL> select * from test1;
EID ENAME
---------- ----------
10 virat
20 rohit
raja
SQL> insert into test1 values(null,null);
1 row created.
SQL> select * from test1;
EID ENAME
---------- ----------
10 virat
20 rohit
raja
SQL> insert into test1 values(30,null);
1 row created.
SQL> select * from test1;
EID ENAME
---------- ----------
10 virat
20 rohit
raja
30
table level::
===========
>create table test1(sno int,name varchar2(10),unique(sno,name));
EX::
SQL> create table test2(eid int,ename varchar2(10),unique(eid,ename));
Table created.
SQL> insert into test2 values(1,'randy');
1 row created.
SQL> select * from test2;
EID ENAME
---------- ----------
1 randy
SQL> insert into test2 values(1,'dan');
1 row created.
SQL> select * from test2;
EID ENAME
---------- ----------
1 randy
1 dan
SQL> insert into test2 values(1,'dan');
insert into test2 values(1,'dan')
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C007645) violated
Comments
Post a Comment