View Full Version : Delete from linked tables
NancyJ
08-19-2005, 04:41 PM
Is it possble to delete all records from a table and all records in a second table that are linked to that record?
Kid Charming
08-19-2005, 05:05 PM
You can use something like:
DELETE
table1
,table2
FROM
table1
,table2
WHERE
table1.id = table2.t1_id
AND
id = x
NancyJ
08-19-2005, 05:23 PM
hmm, didnt work.. probably just another crappy SQL Server thing... rarrr
Kid Charming
08-19-2005, 05:25 PM
What version are you on? It'll only work on version 4.0 and up.
NancyJ
08-19-2005, 05:26 PM
SQL Server 7
Kid Charming
08-20-2005, 12:08 AM
Ah. That code's for MySQL; I don't think SQL Server supports it at all. You should be able to use 'ON DELETE CASCADE' in your table definitions, but you'll need to check the docs for specifics -- I don't feel qualified to say much more than that.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.