Oracle FOREIGN KEY constraint data deletion ____oracle

Source: Internet
Author: User

Today colleagues let me delete a table of data, happy to say yes;

It looks like a simple task, it can be tricky to do, originally this table is a foreign key constraint, as a primary table exists.

But I just got in touch with the system, but it's hard to die.


Then I checked the data. Confirm that the constraint name can be queried to the appropriate table to disable the constraint, which solves the


Here's how I do the experiment:


First build two tables:

CREATE TABLE T_group (ID int not null,name varchar (), primary key (ID));

CREATE TABLE T_user (ID int not null,name varchar (), GroupID int,primary key (ID), foreign key (GroupID) references P (ID));


Insert data:

INSERT into T_group values (1, ' Group1 ');
INSERT into T_group values (2, ' Group2 ');

INSERT into T_user values (1, ' qianxin ', 1);
INSERT into T_user values (2, ' Yiyu ', 2);

Attempt to delete the T_group data error. As shown in Figure I


From the table by dba_constraints query according to the constraint name

Select Constraint_name, Constraint_type, table_name from dba_constraints where Constraint_name=upper (' sys_c005376 ');


Disable constraint below

ALTER TABLE t_user disable constraint sys_c005376;

Try to delete the data again

Delete from T_group;


Delete the success "" "" "The" "" "" "" "," "" "The" "", "" ""


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.