创建新的表,其中字段包含not null 约束:
create table student (sno number(5) primary key,sname varchar2(20) not null,idcard varchar2(18),createtime date default sysdate);
对sname添加unique约束:
alter table student add constraint un_sname unique(sname);
alter table student add constraint un_sname unique(sname)
*
ERROR at line 1:
ORA-02299: cannot validate (SCOTT.UN_SNAME) - duplicate keys found
将sname上的not null约束删掉:alter table student drop constraint SYS_C005598;
再次添加unique约束,才会成功:
alter table student add constraint un_idcard unique(sname);
Table altered.
然后也可以在unique约束上添加not null 约束:
alter table student modify sname not null;
Table altered.