Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting from Multiple Tables

Status
Not open for further replies.

LittleSmudge

Programmer
Mar 18, 2002
2,848
GB
I have two tables that are Import Quarantine tables populated from CSV files.

The tables are linked in a one to many relationship - but as I can't trust the validity of the data I cannot guarantee the referential integrity.

tblImportTest
TestId
field1
field2
etc.

tblImportContent
TestRef ForeignKey to tblImportTest.TestId
field1
field2
etc.

I want to create a patameter query that will delete any records for a matchine TestId from both tables ( IF they exist ) bit remember that I can't guarantee record will exist in either table.


I've tried

Code:
DELETE tblImportTest.*, tblImportContent.*
FROM tblImportTest, tblImportContent
WHERE tblImportTest.TestId = [Test Instance ID To Be DELETED] 
AND tblImportContent.TestRef = [Test Instance ID To Be DELETED];

When I run this I get
"Could not delete from specified tables."


Is there any way of combining a Delete from the two tables into one query ?


G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
I'm afraid you've to play with 2 delete queries:
1) delete the many-side records
2) delete in the main table

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV I'm handing this over to others as of tomorrow ( 8th November ) because my contract has come to an end and I wanted to make it as simple and idiot proof as possible. With any two step process their's always the possibility of missing the second step.

But if it can't be done in one then two it has to be.


Thanks again for the confirmation.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top