国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

在已有冗余的表上加唯一約束

2024-07-21 02:38:49
字體:
供稿:網(wǎng)友

  SELECT * FROM emp a
  WHERE rowid > ANY
  (SELECT rowid FROM emp b
  WHERE a.ename = b.ename
  )
  可以找到冗余的數(shù)據(jù)
  今個發(fā)現(xiàn)還有一個比較簡便的方法,如下使用 exceptions into exceptions;
  
  
    SQL> create table t ( a int, b int, c int );
    表已創(chuàng)建。
    SQL> insert into t select rownum,rownum+1,rownum+2 from all_objects where rownum <5;
    已創(chuàng)建4行。
    SQL> insert into t select *from t where rownum<3;
    已創(chuàng)建2行。
    SQL> commit;
    提交完成。
    SQL> select *from t;
        A     B     C
   ---------- ---------- ----------
        1     2     3
        2     3     4
        3     4     5
        4     5     6
        1     2     3
        2     3     4
    已選擇6行。 SQL> create table exceptions(row_id rowid,
    2 owner varchar2(30),  3 table_name varchar2(30),
    4 constraint varchar2(30));
    表已創(chuàng)建。
    SQL> SQL> alter table t add constraint t_unique
    2 unique(a,b,c) exceptions into exceptions;
   alter table t add constraint t_unique
                  * ERROR 位于第 1 行: ORA-02299: 無法驗證 (EPUSER.T_UNIQUE) - 未找到重復(fù)要害字
    SQL> create table dups
    2 as select *from t where rowid in (select row_id from exceptions);
    表已創(chuàng)建。
    SQL> select *from dups;
        A     B     C
   ---------- ---------- ----------
        1     2     3
        2     3     4
        1     2     3
        2     3     4
    SQL> select row_id from exceptions;
    ROW_ID
   ------------------
   AAAIEJAAKAAAyMSAAA
   AAAIEJAAKAAAyMSAAE
   AAAIEJAAKAAAyMSAAB
   AAAIEJAAKAAAyMSAAF
    SQL> delete from t where rowid in ( select row_id  2 from exceptions );
    已刪除4行。
    SQL> insert into t select distinct * from dups;
    已創(chuàng)建2行。
    SQL> SQL> commit;
    提交完成。
    SQL> select *from t;
        A     B     C
   ---------- ---------- ----------
        3     4     5
        4     5     6
        1     2     3
        2     3     4

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 固安县| 彰武县| 盐边县| 巫溪县| 舞阳县| 舟山市| 重庆市| 平乡县| 彝良县| 望都县| 牡丹江市| 油尖旺区| 龙南县| 兰州市| 探索| 旬阳县| 乐东| 谢通门县| 上蔡县| 玛纳斯县| 双峰县| 丰台区| 稻城县| 嘉祥县| 胶南市| 景泰县| 济南市| 清镇市| 无极县| 新沂市| 荣成市| 平度市| 东山县| 东至县| 泰宁县| 南木林县| 吉林省| 盐城市| 长白| 交城县| 商丘市|