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
 Transact-SQL (2005)
 Table maintenance - One to many relationship

Author  Topic 

eljapo4
Posting Yak Master

100 Posts

Posted - 2010-12-02 : 05:01:22
I'm trying to implement a maintenance plan on Table B, but the problem is that Table B is linked to Table A by an ID Field. There is one record in Table A but there could be many in Table B. What's the best solution for me to delete the data in both tables if the Del_Date field in Table A is > 2years old?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-02 : 05:16:17
You could create a cascade delete trigger.
Probably better to just get a list of the entries from table A into a temp table delete from table B using a join (could use Table A but a temp table allows you to see what it is going to do in testing) then delete from Table A.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -