q1w2e3r4t7 Posted April 19, 2006 Posted April 19, 2006 I have 2 tables (Transactions, Entries) They have a relationship of one Transaction.ID to many Entried.TransID's. i want to be able to delete delete a list of Transactions & the associated linked entries based on a Transaction.Naration Value. How is this possible? i have tried; DELETE FROM dbo.Entries INNER JOIN dbo.Transactions ON dbo.Entries.TransID = dbo.Transactions.ID WHERE (dbo.Transactions.Naration LIKE '" & "Sales" & "') but gives me the following error ; Incorrect Syntax near the keyword 'INNER' as system.data.sqlclient.sqlconnection.onerror I'm only just starting to learn SQL and unsure of what's going wrong here, any assistance would be greatly appreciated. Thanks, (p.s. running vs.2005 VB if it helps) Quote
q1w2e3r4t7 Posted April 19, 2006 Author Posted April 19, 2006 I found an example and it has assisted me deleting records from the Entries table using data from the Transactions table, i had to adjust DELETE FROM dbo.Entries TO DELETE FROM dbo.Entries FROM dbo.Entries" HOWEVER, can anyone please help me adjust this further to also delete the Transaction rows also, or must this be done in a seperate command? Thanks Quote
*Experts* Nerseus Posted April 19, 2006 *Experts* Posted April 19, 2006 They must be deleted separately - a DELETE can only work on one table. You can use alternatives, if your DB has the features. For example, in SQL Server you can turn on cascading deletes (delete from the parent table and it will delete the child rows). You can also code similar functionality in a trigger. It is BY FAR much more common to do the two deletes yourself, deleting from the child tables first and then the parent. I've worked with both kinds of companies - those that prefer to do deletes "by hand" and those that LOVE triggers. I only recently learned about the ability to do cascading deletes and my company's DBA doesn't like them. I trust him enough to take his advice. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
q1w2e3r4t7 Posted April 19, 2006 Author Posted April 19, 2006 Thanks very much Nerseus for the advice. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.