Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2002
    Posts
    78

    Unanswered: would automatically delete all child records when the parent record gets deleted

    FK declaration that would automatically delete all child records when the parent record gets deleted.HOW TO DO IT

    Thanks in advance
    mohan

    SQL> CREATE TABLE M1 (NAME VARCHAR2(10),CLIENT_ID NUMBER CONSTRAINT MM1_C PRIMAR
    Y KEY);



    SQL> CREATE TABLE M2(PHNOE_ NUMBER,CLIENT_ID REFERENCES M1(CLIENT_ID) );




    SQL> select * from m1;

    NAME CLIENT_ID
    ---------- ----------
    MOHAN 1
    ALLWYN 2



    SQL> select * from m2;

    PHNOE_ CLIENT_ID
    ---------- ----------
    255666 1

  2. #2
    Join Date
    Mar 2003
    Location
    Moscow
    Posts
    4

    ON DELETE CASCADE

    CREATE TABLE M2(PHNOE_ NUMBER,CLIENT_ID REFERENCES M1(CLIENT_ID) ON DELETE CASCADE);

  3. #3
    Join Date
    Jan 2003
    Location
    Woking
    Posts
    107

    Re: would automatically delete all child records when the parent record gets deleted

    Originally posted by mohan
    FK declaration that would automatically delete all child records when the parent record gets deleted.HOW TO DO IT

    Thanks in advance
    mohan

    SQL> CREATE TABLE M1 (NAME VARCHAR2(10),CLIENT_ID NUMBER CONSTRAINT MM1_C PRIMAR
    Y KEY);



    SQL> CREATE TABLE M2(PHNOE_ NUMBER,CLIENT_ID REFERENCES M1(CLIENT_ID) );




    SQL> select * from m1;

    NAME CLIENT_ID
    ---------- ----------
    MOHAN 1
    ALLWYN 2



    SQL> select * from m2;

    PHNOE_ CLIENT_ID
    ---------- ----------
    255666 1
    Mohan,
    This is how you do it.
    While creating the table m2, you add the following line
    "ON DELETE CASCADE"

    so your create statement will be

    CREATE TABLE M2(PHNOE_ NUMBER,CLIENT_ID REFERENCES M1(CLIENT_ID) on delete cascade )

    Hope it Helps.
    nn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •