Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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)

Posted

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

  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...