91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

數據庫更新表數據時出現ORA-02292錯誤怎么解決

發布時間:2021-12-22 09:44:23 來源:億速云 閱讀:1179 作者:iii 欄目:關系型數據庫

本篇內容介紹了“數據庫更新表數據時出現ORA-02292錯誤怎么解決”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

在更新表的主鍵字段或DELETE數據時,如果遇到ORA-02292: integrity constraint (xxxx) violated - child record found 這個是因為主外鍵關系,下面借助一個小列子來描述一下這個錯誤:

實驗:
--建立主表
SQL> create table student(id  number,name nvarchar2(12),constraint pk_student primary key(id));

Table created.

--建立外鍵約束表
SQL> create table grades(id  number ,subject nvarchar2(12),scores number,constraint pk_grades primary key(id ,subject),constraint fk_student_id foreign key(id) references student(id));

Table created.

SQL> insert into student values(1001,'kerry');

1 row created.

SQL> insert into student values(1002,'jimmy');

1 row created.

SQL> commit;

Commit complete.

SQL> insert into grades values(1001, 'math', 120);

1 row created.

SQL> insert into grades values(1001, 'english', 106);

1 row created.

SQL> commit;

Commit complete.

--查看:
SQL> select * from student;

        ID NAME
---------- ------------------------
      1001 kerry
      1002 jimmy

SQL> select * from grades;

        ID SUBJECT                      SCORES
---------- ------------------------ ----------
      1001 math                            120
      1001 english                         106

--更新主表列
SQL> update student set id=1004 where name='kerry';
update student set id=1004 where name='kerry'
*
ERROR at line 1:
ORA-02292: integrity constraint (SYS.FK_STUDENT_ID) violated - child record
found


--報錯,解決:首先找到外鍵約束和相關表,禁用外鍵約束,處理數據,然后啟用外鍵約束:查詢dba_constraints
SQL> col OWNER for a10
SQL> select owner,CONSTRAINT_NAME,TABLE_NAME,SEARCH_CONDITION,VALIDATED from dba_constraints where constraint_name='FK_STUDENT_ID';

OWNER      CONSTRAINT_NAME                TABLE_NAME                     SEARCH_CONDITION               VALIDATED
---------- ------------------------------ ------------------------------ ------------------------------ -------------
SYS        FK_STUDENT_ID                  GRADES                                                         VALIDATED

SQL>

--disable約束:
SQL> alter table sys.grades disable constraint FK_STUDENT_ID;

Table altered.

SQL>
SQL> update student set id=1004 where name='kerry';

1 row updated.

SQL> commit;

Commit complete.

SQL> update grades set id=1004 where id =1001;

2 rows updated.

SQL> commit;

Commit complete.

--修改完后,再enable約束:
SQL> alter table sys.grades enable constraint FK_STUDENT_ID;

Table altered.

--查看:
SQL>  select * from student;

        ID NAME
---------- ------------------------
      1004 kerry
      1002 jimmy

SQL> select * from grades;

        ID SUBJECT                      SCORES
---------- ------------------------ ----------
      1004 math                            120
      1004 english                         106

SQL>


---如果是刪除數據遇到這種情況,可以先刪除子表數據,然后刪除父表數據,如下:
SQL> delete from student where id=1004;
delete from student where id=1004
*
ERROR at line 1:
ORA-02292: integrity constraint (SYS.FK_STUDENT_ID) violated - child record found

--先刪除子表中相關列數據,
SQL>  delete from grades where id in ( select id from student where id=1004);

2 rows deleted.

--再次刪除
SQL>  delete from student where id=1004;

1 row deleted.

SQL> commit;

Commit complete.

SQL> select * from student;

        ID NAME
---------- ------------------------
      1002 jimmy

SQL> select * from grades;

no rows selected

SQL>

“數據庫更新表數據時出現ORA-02292錯誤怎么解決”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

新乡市| 泰顺县| 涿州市| 法库县| 湟源县| 安吉县| 周口市| 惠来县| 龙川县| 洛宁县| 怀远县| 临城县| 嘉义县| 益阳市| 张家口市| 白河县| 鄱阳县| 建平县| 许昌市| 夹江县| 克东县| 丰都县| 太仓市| 墨脱县| 含山县| 砀山县| 仁布县| 鄯善县| 武邑县| 屏东县| 汉中市| 比如县| 宁南县| 鲁甸县| 彝良县| 澄城县| 湘潭县| 西华县| 同江市| 正宁县| 台山市|