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 2000 Forums
 SQL Server Development (2000)
 delete

Author  Topic 

supersql
Yak Posting Veteran

99 Posts

Posted - 2007-05-04 : 14:02:28
how can I delete a record when that is referenced by some other table. I just delete all records where ever that is referenced.

what i mean is when i delete a row all the child rows related to tht field shud also delete.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-04 : 14:12:55
You first delete the child rows from the child tables, then you can delete the parent rows from the parent table. If you want SQL Server to handle deleting the child data for you, then you can either setup cascading deletes on the foreign key or create a delete trigger on the parent table. I'd opt for the cascading deletes on the FK.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -