#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    18
    Rep Power
    0

    Problems with "Delete" statement in SQL


    Hi,

    I have the table: R1(A, B, C)

    Primary Key (A, B)
    Foreign Key (A)

    I'm trying to delete a row using the query:
    delete from R1 where A = 123;

    However, Oracle freezes on me. Please help. Thanks.
  2. #2
  3. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Canada
    Posts
    305
    Rep Power
    11
    Primary and foreign keys are defined the parent/child relationship, you cannot delete a record from parent table until it has record in child table. I think your parent table R1 has any child record that's why oracle does not allow to delete this parent record because oracle respects the parent/child relationship. For your future reference you should define keyword ON DELETE CASCADE with your primary key, this key implicitly delete the child records when you try to delete parent record. But this time delete the associative child record of this primary key from the child table then delete it from parent table.


    Regards

IMN logo majestic logo threadwatch logo seochat tools logo