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
 deleting tables with multiple guids

Author  Topic 

TiaBag
Starting Member

1 Post

Posted - 2011-02-15 : 15:28:23

Guys,
wonder if someone could help.
I am trying to delete items from multiple tables.

From table A, I want to delete everything. This table contains a guid which is referenced other tables e.g. table B and C. These tables also include guids to identify them plus other guid references.

How do I delete everything from Table A, delete those items from table B where my guid from table A is referenced. Table B also contains other guids which references a different tables. I need to delete these references also.
Any ideas on how I would go about this task?

thanks

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-02-16 : 06:28:25
http://stackoverflow.com/questions/2788575/tsql-script-to-add-delete-cascade-to-existing-tables

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-02-16 : 06:30:36
Or do it manually in reverse.

DELETE b
FROM
tableB AS b
JOIN tableA AS a ON a.[<yourColumn] = b.[yourColumn]

DELETE c
FROM
tableC AS c
JOIN tableA AS a ON a.[<yourColumn] = c.[yourColumn]

DELETE a
FROM
tableA AS a


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

shamasm
Starting Member

11 Posts

Posted - 2011-02-16 : 06:48:49
You want to delete Table A alone or other two tables B and c also
Go to Top of Page
   

- Advertisement -