亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

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

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

數據庫更新表數據時出現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

岑溪市| 太仆寺旗| 新化县| 中方县| 南召县| 萍乡市| 扎赉特旗| 江达县| 河源市| 阳高县| 新津县| 呼和浩特市| 开平市| 仲巴县| 文成县| 双峰县| 海南省| 陇南市| 疏附县| 延庆县| 彩票| 鄂托克前旗| 滁州市| 蕲春县| 深圳市| 宣城市| 山西省| 达孜县| 岐山县| 天长市| 班戈县| 瑞昌市| 子洲县| 永丰县| 清水县| 华容县| 曲周县| 星子县| 织金县| 德惠市| 曲阜市|