...

View Full Version : Delete from linked tables



NancyJ
08-19-2005, 03: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, 04: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, 04:23 PM
hmm, didnt work.. probably just another crappy SQL Server thing... rarrr

Kid Charming
08-19-2005, 04:25 PM
What version are you on? It'll only work on version 4.0 and up.

NancyJ
08-19-2005, 04:26 PM
SQL Server 7

Kid Charming
08-19-2005, 11:08 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum