在有重復(fù)數(shù)據(jù)的列上添加unique constraints,大家正常的解決辦法就修改重復(fù)數(shù)據(jù),但也可以 保留重復(fù)數(shù)據(jù),使約束對以后的數(shù)據(jù)有限制,不過我們還可以用以下的方法來添加唯一約束. SQL create table aa(num number(6),email varchar2(32)); 表已創(chuàng)建。 SQL insert
在有重復(fù)數(shù)據(jù)的列上添加unique constraints,大家正常的解決辦法就修改重復(fù)數(shù)據(jù),但也可以
保留重復(fù)數(shù)據(jù),使約束對以后的數(shù)據(jù)有限制,不過我們還可以用以下的方法來添加唯一約束.
SQL> create table aa(num number(6),email varchar2(32));
表已創(chuàng)建。
SQL> insert into aa values(1,'11');
已創(chuàng)建 1 行。
SQL> insert into aa values(2,'11');
已創(chuàng)建 1 行。
SQL> commit;
提交完成。
SQL> alter table aa add constraint aa_un unique(email) ;
alter table aa add constraint aa_un unique(email)
*
第 1 行出現(xiàn)錯(cuò)誤:
ORA-02299: 無法驗(yàn)證 (PERFSTAT.AA_UN) - 找到重復(fù)關(guān)鍵字
SQL> create index aa_inx on aa(email);
索引已創(chuàng)建。
SQL> alter table aa add constraint aa_un unique(email) enable novalidate;
表已更改。
SQL> commit;
提交完成。
SQL> insert into aa values(1,'11');
insert into aa values(1,'11')
*
第 1 行出現(xiàn)錯(cuò)誤:
ORA-00001: 違反唯一約束條件 (PERFSTAT.AA_UN)
SQL>
----- end --------
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com