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
 General SQL Server Forums
 New to SQL Server Programming
 delete child if parent deleted

Author  Topic 

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-03-15 : 06:48:42
dear friend,,
i have two table.in my first table id is primarykey and in my second table id if foreign key. so my need i have to use one query to delete the primary key table values. so if i am deleting one id in primary key table the child in the second table has to be deleted automatically.if parent get deleted the child should get deleted automatically. so plese help me to do this please give me sample query please

dineshasanka
Yak Posting Veteran

72 Posts

Posted - 2008-03-15 : 08:17:37
For the foreign key constraint, enable cascade delete. In that case it child records will be deleted automatically

---------------------
http://dineshasanka.spaces.live.com/
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-03-15 : 11:33:23
dear dineshasanka,

thanks for the help
Go to Top of Page
   

- Advertisement -