Cascade Constraint

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonia.sardana
    New Member
    • Jul 2006
    • 95

    Cascade Constraint

    Que-What is the use of CASCADE CONSTRAINTS?

    Ans-When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.

    Example

    create table primary1(roll int primary key,name varchar)
    insert into primary1 values(1,'A')
    insert into primary1 values(2,'B')
    select * from primary1


    create table foreign1(roll1 int references primary1(roll), address varchar(10))
    insert into foreign1 values(1,'Delhi ')
    insert into foreign1 values(2,'Fbd')
    select * from foreign1

    If i write DROP TABLE PRIMARY1,table cannot be dropped.Its right.

    If i write drop table primary1 CASCADE, it means that primary1 table can be deleted even if it referenced by foreign1....... .....If i m not wrong.......

    But the primary1 table is not deleting when i write drop table primary1 CASCADE,
    ERROR is coming Incorrect syntax near the keyword 'CASCADE'.

    Your Prompt Reply will be appreciated.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Where did you get that answer? I believe CASCADE can be used in deleting records, not dropping the entire table.

    Here's more.

    -- CK

    Comment

    • sonia.sardana
      New Member
      • Jul 2006
      • 95

      #3
      Dear CK ,i have read this from book navathe and from the site

      http://www.careerencla ve.com/freshers-walkins.htm--> Then click on Right hand side-->database FAQs-->SQL interview Q&A - 2 -->Question No 11.

      Read it & pleas reply

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Here's the complete DROP TABLE syntax. I don't see any CASCADE on it.

        I could be mistaken. He could be right.

        -- CK

        Comment

        Working...