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
 Other SQL Server Topics (2005)
 Deleting Records in Referenced Tables

Author  Topic 

mike83
Starting Member

2 Posts

Posted - 2009-12-22 : 07:12:13
Hi guys
Does anyone have a tool or a method for deleting records from tables which have foreign key references in other tables without deleting
the referenced records one after the other.
Thanks.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-12-22 : 07:27:40
Cascading delete maybe?
Go to Top of Page

mike83
Starting Member

2 Posts

Posted - 2009-12-23 : 06:03:54
Thanks RickD. I think thats what I need.
Go to Top of Page

behrman
Yak Posting Veteran

76 Posts

Posted - 2009-12-25 : 21:37:42
In the design of the foreign key you can specify a delete rule. Like you said the CASCADE option is what you need. The following is from BOL:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/uirfsql9/html/08812343-e9a6-4a0f-91fd-80d95ab4b71f.htm

INSERT and UPDATE Specification Category
Expand to show information for the Delete Rule and the Update Rule for the relationship.

Delete Rule
Specify what happens if a user tries to delete a row with data that is involved in a foreign key relationship:
No Action An error message tells the user that the deletion is not allowed and the DELETE is rolled back.
Cascade Deletes all rows containing data involved in the foreign key relationship.
Set Null Sets the value to null if all foreign key columns for the table can accept null values. Applies to SQL Server 2005 only.
Set Default Sets the value to the default value defined for the column if all foreign key columns for the table have defaults defined for them. Applies to SQL Server 2005 only.

RAQ Report: Web-based Excel-like Java reporting tool
Go to Top of Page
   

- Advertisement -