Error during DELETING foreign key violation lasts to self referential FK

DB version: 10 gr 2

In the example below, I have a self referencing foreign key mgr. When I DELETE records
I don't get an error ORA-02292 of self referencing FK.
create table emp2 
 (
 empno number primary key,
 mgr   number references emp2( empno )
 );

Table created.



INSERT INTO EMP2 VALUES (2,2);

INSERT INTO EMP2 VALUES(3,NULL);

INSERT INTO EMP2 VALUES (4,3);

COMMIT;

SQL>DELETE FROM EMP2;

3 rows deleted.
But in one of our tables of Production which has an auto referential FK, I get an error similar to
ERROR at line 1:
ORA-02292: integrity constraint (SCOTT.EMP2_FK) violated - child record found
When I try to delete records. No idea why I get this error?

Hi Garry,

Your FK said "all Manager must be an employee."

If this statement

DELETE FROM EMP3 WHERE EMPNO<5;

which is a gross violation from the Manager of EMPNO = 6 would not be an employee.

How do you solve that?

Expected EMPNO = deleted 6?
Should EMPNO = 6 I have a new Manager?
Should EMPNO = 6 has no handler?

But,

GarryB wrote:
Update the child column with null did not make a difference either (I always got the error).

Not in my book, is not

SQL> UPDATE EMP3 SET MGR = NULL
WHERE MGR <5
4 rows updated.
SQL> DELETE FROM EMP3 WHERE EMPNO<5
3 rows deleted.
SQL> SELECT * FROM EMP3

     EMPNO        MGR
---------- ----------
         6
1 row selected.

Concerning
Peter

Tags: Database

Similar Questions

  • Foreign key violation when creating form adf

    I have a form of document create and after that the user send the form, the form data is saved in the table in the document before the transfer to the file for this record loading screen. The document table has a foreign key to the attachments table. The first time, it works fine, but when I try to create a new one, I got the following error message:

    Houston-26048: constraint "ATT_SSSID_FK" violated during the post operation: "Update" using the SQL query "UPDATE DOCUMENT_INFO SET DOC_SSSID = DocumentInfo?, DOC_AGENCYID =?, DOC_DOCUMENTTYPEID =? WHERE DOC_SSSID =? ».
    ORA-02292: integrity constraint (SSS. ATT_SSSID_FK) violated - book of the foundling

    I don't know why she strives to update the record rather than create a new one. Reminds you of someone please where he could be the problem?

    Thank you very much!

    Looks like the current record is one that you just created.

    When you create a new record, remember that you use the CreateInsert action (and not only create) in the definition of the page.

  • I get an error when deleting the keys when I try to delete the registry keys under Vista

    I was able to get permissions on the key, but I can't remove key. He said cannot remove the CdRom & Ven_YMAX & Prod_magicJack & Rev_3. 00 error while deleting key

    jcr442

    You shouldn't go around deleting keys. Why do you really want to delete this key? What program the key belongs? Uninstall the program only removes the key? Otherwise, try to uninstall it in safe mode, or go to the manufacturer's website to see if they have a problem. They have a tool to remove the application. If the program has recently been installed you can also use system restore to remove it. Thank you, Jeremy M - Support Engineer

  • "File permission error" during deleting files on Windows 7

    Hello

    I'm running Labview 2011 and have an application that has been developed to run on Windows XP. The part of the application deletes a file from the System32 folder, and then replaces it with another version of the same file (based on a specific condition). It worked perfectly on Windows XP. Now that I've migrated to Windows 7, I changed the path to access the SysWOW64 folder, where now stands the same file. Now when I run the program, during the phase of elimination, I get the following error:

    Possible reasons:

    LabVIEW: File permission error. You do not have the correct permissions for the file.

    When I try to manually delete the file in the SysWOW64 folder, I get a popup to confirm the progress of the removal. The file is then deleted.

    Is there anyway that I can get permission to delete the file is automatically? I also tried to use the "Set permission" VI with the permission set to 511 (octal 777) but that VI also threw up the same file permission error.

    Any help would be greatly appreciated.

    Thank you

    Arun

    Try to run your application with the option "Run As Administrator".  Windows 7 is very restrictive on who can do what.  It's generally a bad idea that requires deleting file to a system folder.  I think you should consider using a temporary directory to avoid this problem.

  • Is a foreign key MUST have a UNIQUE or PK column as a reference?

    First I tried, from what I saw Yes it must be Unique or PK. Secondly, I am pretty sure that I read somewhere where there are PK or unique. Thirdly, I checked oradocs and other pages, the thing ends, I owe an answer

    Constraint foreign key (also called a constraint referential integrity) designates a column as a foreign key and establishes a relationship between this foreign key and a primary or unique key specified, called the referenced key.


    This implies, but does not explicitly specify that it MUST be a PK or a SINGLE.


    Basically I want a simple yes/no answer just to give me some peace of mind. I don't want to waste any time, but changes to the oracle from time to time, and I'd rather have a confirmation from someone with more knowledge/experience.


    Thank you!

    Yes.

    This same document you are referencing tells you what are the rules for the creation of a foreign key.

    Data integrity

    Foreign key constraints

    Whenever two tables have one or more common columns, Oracle database can apply the relationship between the two tables with a foreign key, also called a referential integrity constraint constraint. The constraint requires that for each value in the column on which the constraint is defined, the value in the other specified that another table and column must match. An example of a referential integrity rule is that an employee may work for only one Department.

    Table 5-2 lists the terms associated with referential integrity constraints.

    Table 5-2 referential integrity constraint conditions

    Term Definition

    Foreign key

    The column or set of columns included in the constraint definition that refers to a key that is referenced. For example, the department_id column employees is a foreign key that refers to the department_id column of departments .

    Foreign keys can be described as several columns. However, a composite foreign key must refer to a primary or unique key with the same number of columns and the same types of data.

    The value of the foreign keys can be either the primary or unique key value referenced or be null. If any column of a composite foreign key is null, then the portions not null the key do not match any corresponding part of a parent key.

    Referenced key

    The unique key or the primary key of the table referenced by a foreign key. For example, the department_id column departments is the key referenced to the department_id column of employees .

    Table dependent or child

    The table containing the foreign key. This table is based on the values present in the primary or unique key referenced. For example, the employees table is a child of departments .

    Referenced or the parents table

    The table that is referenced by the foreign key of the child table. It is the key to this table reference that determines whether specific inserts or updates are allowed in the child table. For example, the departments table is a parent of employees .

    The first three terms defined in the table EXPLICITLY State references to the 'core' or 'unique' keys to the parent.

    The doc also refers to the Application Developer Guide:

    Maintaining the integrity of the data in Database Applications

    Foreign key references a primary key by default

    If the list of columns is not included in the REFERENCES option when you set a FOREIGN KEY constraint (simple or composite column), then Oracle database assumes that you want to reference the primary key of the specified table. You can also explicitly specify the columns to reference the table parent in parentheses. Oracle database checks automatically to check this list of column refers to a primary or unique to the parent table key. If it isn't, an informative error is returned.

    That the entire paragraph is as explicitly as it gets.

    No list of columns? Oracle then checks for a primary key.

    There is a list of columns? Then Oracle 'control to verify this list of column made reference to a primary or unique key'...

  • How can I get the data in the foreign key?  PHP/mysql

    I managed to create registration, log-in and results pages appear for accounts of client with PHP/Mysql/Dreamweaver 8. I have another page for more information to be contained in a child table, I used the Insert Wizard to create. I can't make it work. I get either a foreign key cannot be null error or a foreign key constraint.

    If I include the foreign key in the form on the page, I can manually enter the appropriate identification number, and it works. How to automatically enter the id into the foreign key column?

    I got the authentication of users using e-mail, password and user type.

    Thanks for your help

    When someone connects, Dreamweaver creates a session variable called $_SESSION ['MM_Username"]. Use this session variable to create a recordset object to get the ID of the user, who can then be entered in the child table's foreign key field.

    Dreamweaver automatically updates the code for recordsets immediately above the DOCTYPE declaration, then you will need to move above the code for the server behavior insert record. So it must be in the following order:

    1. Recordset to get the user ID
    2. Insert the record to the child table
  • correct handling of foreign keys in unique constraints for operations ON DELETE SET NULL

    During my troubleshooting at a client site, I came across an interesting setup where I would like to ask your opinion.


    Consider two tables ADTB and TBLB.

    ADTB:

    INT COLA1

    COLA2 INT

    TBLB:

    COLB1 INT

    COLA2 is COLB1 as a foreign key ON DELETE SET NULL value.

    COLA1 and COLA2 are combined into a UNIQUE for the BATTERY constraint.

    I have two records of TBLB:

    (1)

    (2)

    and two DRUM recordings:

    (1, 1)

    (2, 2)

    so far, all the constraints are valid.

    During my research, I learned that I can not put COLA2 null in ADTB for two lines at the same time:

    TBLA UPDATE set COLA2 = NULL where COLA1 = 1;

    -> OK

    TBLA UPDATE set COLA2 = NULL where COLA1 = 2;

    -> VIOLATED UNIQUE CONSTRAINT

    Unfortunately, it's something my application needs, anyway. In order to get this resolved, but I try to understand, what would happen if I:

    REMOVE THE TBLB;

    ?

    It should set COLA2 in ADTB "Null" on the two lines, which is not allowed due to the UNIQUE CONSTRAINT.

    Can someone shed light on this issue? Thank you.


    Yours,

    Ronny

    Unfortunately, as you say, you can't not NULL values in such a unique constraint.  It would be the same as if you had a composite primary key and try to allow one of the columns will be null in several rows with the same value in the other column.  NULL is treated as an "unknown" value, it is possible that it could be the same value (it may or may not be, but Oracle does not know), so it must assume that it might be and that's why treat it as if there is the potential for a duplicate... so it's not unique.

    In short, do not allow null values in your unique constraints.

    The default is in the drawing, not in the way that Oracle is the treatment.  Fix the design if you do not have NULL values.

    In terms of relational database design, it seems that you are trying to transform the 1:M relations M:M relations, and which requires an intermediate table if you have M:1 and 1:M between 3 tables instead.

  • integrity of foreign key error

    I had the departments and officials from two tables
    employee table has a foreign key that is a primary key in the departments table
    IE department_id
    every time I try to delete records from the employee table using the department_id IE a foreign key
    then it displays error
    but when I do it through other constraints then the lines are to remove
    so why can't delete lines in the employees table using department_id which is a foreign key in the employees table
    and the primary key for the departments table?

    guys, it's really easy when you really look at the error message:

    The violation is not the FK on employees.department_id. (the name will be EMP_DEPT_FK)
    The violation is against the FK hr.dept_mgr_fk which refers to the column manager_id (employee id) in the departments. When you try to remove all dept 50 employees, you also try to remove the service manager, but which is not allowed due to the FK of departments. Try this:

    update departments set manager_id = null where id = 50;
    delete from employees where department_id = 50;
    

    Bjoern

  • Foreign key DML error

    My apologies if this has been answered here already, but I did some research and could not find a matching problem.

    I have a table called messages, defined as follows:

    < pre >
    -set the table
    (Messages) CREATE TABLE
    ID NUMBER CONSTRAINT pk_messages_id PRIMARY KEY,
    title VARCHAR2 (255),
    body VARCHAR2 (4000).
    created_at TIMESTAMP,
    removed_at TIMESTAMP
    );
    < / pre >

    And I have a table of junction, called organization_messages, defined as follows:

    < pre >
    CREATE TABLE organization_messages)
    organization_id VARCHAR2 (12),
    message_id NUMBER,
    CONSTRAINT fk_org_message_id
    FOREIGN KEY (message_id)
    Messages of REFERENCES (id)
    ON DELETE CASCADE
    );
    );
    < / pre >

    I did this so that when a message is deleted, the join in organization_messages line would be deleted automatically, via the ON DELETE CASCADE.

    I got your basic DML processing going on for the messages table in the APEX, but now that I've added the foreign key, I get this when I try to delete a line of messages:

    < pre >
    ORA-02291: integrity constraint (PASSPORT. FK_ORG_MESSAGE_ID) violated - key parent not found
    Error failed to update org assignments.
    Ok
    < / pre >

    What is the problem? Treatment of DML supplant triggers or the cascades? This work should and I don't have to put in place of the page process to remove lines to join first table... I have it back?

    Thanks for the pair of eyes ;-)

    Billy

    Hello

    AFAIK, using the option delete cascade is the method to use (of course, you can do all this "manually" but that shouldn't be necessary). The only thing I can think is that something is executed on the table organization_messages that can interfere with normal sql features - perhaps another page process and/or a trigger on a table?

    Andy

  • Foreign Key ON DELETE RESTRICT

    Hello

    I m doing error when using the foreign key, could you let me know if there is a syntax error.

    Rank of CREATE TABLE (course_no VARCHAR2 (33) NOT NULL,)

    student_id VARCHAR2 (33) NOT NULL,

    grade VARCHAR2 (2),

    CONSTRAINT FK_COURSE

    FOREIGN KEY (course_no) REFERENCES race (course_no) ON DELETE RESTRICT

    );

    Error report:

    SQL error: ORA-00905: lack of keyword

    Thank you

    There is no keyword to remove not limited to Oracle.  Stop the removal of the parent if there is a child is the default unless overridden by a waterfall, or null.  Otherwise, you can never delete a parent in Oracle.

    John

  • Foreign keys without ON DELETE CASCADE; Database design question

    It's the 3rd company, while I work, where I see that created foreign keys
    ON DELETE CASCADE
    clause.
    My colleague said that it is created without the ON DELETE CASCADE clause in order to complicate the deletion of data (records of children). Thus, for codes of the Purge and archive, before we delete the parent table we must remove from the child table first.

    Occasinaly, something is wrong and we will end up disabling FKs make them all and then purging, archiving, etc...

    So, is it not better to create foreign keys with the clause ON DELETE CASCADE, rather than having all these hassles?

    Experience, no matter what you think?

    Personally, I am firmly in the removal of the brand of hard data camp. In the vast majority of cases, trying to remove an active parent is an error if the user must be informed of what they are trying to do and must make a conscious effort to do so (in other words, remove first the children).

    John

  • Foreign key Error Message ORA - 01430

    I have a LSU_INTER_RESOURCES_T table name. I would like to add a constraint foreign key with the following command:

    ALTER table lsu_inter_message_t
    Add constraint inter_message_id_fk
    inter_request_id lsu_inter_requests_t (inter_request_id) ON DELETE CASCADE REFERENCES;

    The system returned the error message:
    ORA - 01430: added column already exists.

    If I drop the inter_request_id column I'll lose data, and when I create the constraint it places the column at the end of the table. Data loss is not a problem now because the table has no data, but down the line, I see that there is a real problem.

    I would like to have the foreign key defined in the sequence column, I chose when I designed the tabular presentation. IE I want to all key columns placed at the beginning of the table online.

    Can I move the column after that I have set it and how this is done? Is this a feature of 10g?

    Thank you, Ned

    Try

    alter table lsu_inter_message_t
    add constraint inter_message_id_fk
    foreign key(inter_request_id ) REFERENCES lsu_inter_requests_t(inter_request_id) ON DELETE CASCADE;
    
  • Database error: key Violation.

    Hi all

    I face this problem while I try to add a user in the comic book.

    Database error: key Violation.
    ORA-00001: unique constraint (PRD. PK_DRIVER_007) violated.

    May - so that someone knows how to fix this?

    Thank you

    The power function

    you have created the index on Resourceid column of the table of driver which is unique, but you're insterting data dubplicate.

    So either delete this index

    Drop index PK_driver_007;

    Or donot insert duplicate values in Resourceid driver table column.

  • SQL statement error INSERT The conflicted with the FOREIGN KEY constraint

    I recently installed a reporting for vmware vsphere software, but I get a SQL error. I opened a request for assistance with vmware, but so far they have not come up with a solution. The error is caused by: com.microsoft.sqlserver.jdbc.SQLServerException: instruction INSERT The conflicted with the FOREIGN KEY constraint 'FK_CB_VSM_NETWORK_VC_ID '. The conflict occurred in database 'VCChargebackVCC02', table "dbo." " CB_VSM_SERVER', column 'VC_ID '. I don't know a lot about SQL, so I'm lost in the extent of troubleshooting is concerned. If anyone has any ideas I'd love to hear them.

    SQL questions are better posed on Technet.  They are better equipped to manage the

    http://social.technet.Microsoft.com/forums/en-us/categories/

  • Delete data table Parent and child data automatically delete or the value null in the foreign key of the child table.

    Oracle 10g

    Hi gurus

    I test_mst table that has a primary key test_mst.test_id, I detail table test_dtl which has test_dtl.test_id of foreign key, now I have that I want to use the delete statement in test_mst then it should also remove the constraint of her child or null in test_dtl.test_id, can again do in oracle 10g?

    Thanks in advance

    Hi Mit.

    example of cascade

    create table bill(
      bill_id number not null primary key
    )
    ;
    create table bill_item(
      bill_item_id number not null primary key,
      bill_id number references bill(bill_id) on delete cascade
    )
    ;
    insert into bill values (1)
    ;
    insert into bill_item values (1, 1)
    ;
    delete bill
    ;
    select * from bill_item
    ;
    drop table bill_item purge
    ;
    drop table bill purge
    ;
    
    Table BILL created.
    Table BILL_ITEM created.
    1 row inserted.
    1 row inserted.
    1 row deleted.
    
    no rows selected
    
    Table BILL_ITEM dropped.
    Table BILL dropped.
    

    exemplary null

    create table employer(
      employer_id number not null primary key
    )
    ;
    create table employee(
      employee_id number not null primary key,
      employer_id number references employer(employer_id) on delete set null
    )
    ;
    insert into employer values (1)
    ;
    insert into employee values (1, 1)
    ;
    delete employer
    ;
    select * from employee
    ;
    drop table employee purge
    ;
    drop table employer purge
    ;
    
    Table EMPLOYER created.
    Table EMPLOYEE created.
    1 row inserted.
    1 row inserted.
    1 row deleted.
    
                                EMPLOYEE_ID                             EMPLOYER_ID
    --------------------------------------- ---------------------------------------
                                          1                                       
    
    Table EMPLOYEE dropped.
    Table EMPLOYER dropped.
    

Maybe you are looking for