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
 cant delete record due to foreign key

Author  Topic 

ajm22386
Starting Member

1 Post

Posted - 2009-04-17 : 03:34:29
Hi i have a users table with PKEY(Audit_user) this is referenced by every other table to track changes. I need to delete 200 users from users table without amending any other table? Im new to this really need help.Using sql server 2005

Thanks so much.

Joe

joedahoe

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-17 : 03:42:51
BEGIN TRAN

DELETE aux
FROM AuxiliaryTable AS AUX
INNER JOIN Users AS u ON u.UserID = aux.UserID
WHERE u.FirstName = 'Whiskey'

DELETE
FROM Users
WHERE FirstName = 'Whiskey'

COMMIT TRAN



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-17 : 10:12:58
if you had created the foreign key with ON DELETE CASCADE then this removal would have happened automatically without you writing this removal logic for auxiliary tables
Go to Top of Page
   

- Advertisement -