Results 1 to 4 of 4

Thread: ON DELETE CASCADE option

  1. #1
    Contributing Member
    Join Date
    Sep 2007
    Answers
    35

    ON DELETE CASCADE option

    Can I add ON DELETE CASCADE option to an existing FOREIGN KEY using alter.


  2. #2
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: ON DELETE CASCADE option

    Yes that can be specified.


  3. #3
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: ON DELETE CASCADE option

    First you drop the existing constraint.

    Alter table drop constraint constraintname;

    ex:- alter table drop constraint fk_dept

    Then once again add the constraint.

    alter table add constraint constraintname foreign key(deptno)
    references dept(deptno) on delete cascade

    ex:- alter table add constraint dept_emp foreign key(deptno)
    references dept(deptno) on delete cascade

    Last edited by krishnaindia2007; 11-22-2007 at 04:48 AM.

  4. #4
    Expert Member
    Join Date
    Apr 2007
    Answers
    500

    Re: ON DELETE CASCADE option

    First Drop foreign key constraint using below command
    alter table emp drop constraint fk1
    After that add fk constraint, cascade option using this command
    ALTER TABLE dept
    ADD CONSTRAINT fk1
    FOREIGN KEY (deptno)
    REFERENCES emp(dno) ON DELETE CASCADE;


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact