Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 On Delete Cascade

Author  Topic 

rammohan
Posting Yak Master

212 Posts

Posted - 2008-08-08 : 07:51:41
Dear All,
I Have Two Tables:
table1:
id primary key
name
table2:
id1
id references table1(id)
details.

now i have 10 records in each table.
how can i set the ondelete cascade for id column.
if i delete id in table1, the records with id in table2 should automatically deleted.
please tell me how to set ondelete cascade in this situation

One can never consent to creep,when one feels an impulse to soar
RAMMOHAN

NeilG
Aged Yak Warrior

530 Posts

Posted - 2008-08-08 : 07:59:14
Just add the on delete cascade command at the end of the foreign key i.e

CONSTRAINT FK_TABLE1_TABLE2 FOREIGN KEY (ID)
REFERENCES TABLE1 (ID) ON DELETE CASCADE



***************************
Life is for having Fun, and then a little work
Go to Top of Page
   

- Advertisement -