Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: Re: SQL Delete Query


Message #1 by "Jeff Graves" <jeff@i...> on Thu, 25 Jul 2002 21:17:25
Thanks for this post. It helped alot in the Access Database I was working 
on. I have another question though. Say you have mulitple tables. Table1, 
Table2, and Table3. Table1 contains a Primary Key and tables 2&3 have a 
field related to that key. How would you craft an SQL statement to delete 
all records either of tables 2&3 that have a corresponding record in 
Table1?

> Thanks Brian,
> 
> You are indeed correct.  I tried adding a key autonumber field to 
Deletes 
> but that didn't work.  But making recnum in deletes a key field did.  
And 
> I made recnum in the n00ha table a key field for good measure.
> 
> Thanks tremendously.  I would not have figured this out on my own.
> 
> Vic
> 
> I have an important tho probably simple SQl problem
> > Need help, please. I have two tables, Deletes and n00ha.  Deletes 
> consists 
> > of one field, recnum, containing the record numbers in n00ha that I 
want 
> > to delete.  My SQL query in Access 2000 looks like this:
> > 
> > DELETE n00ha.*, n00ha.RECNUM
> > FROM n00ha, Deletes
> > WHERE (((n00ha.RECNUM)=[Deletes].[recnum]));
> > 
> > 
> > When I click on the view button I get the 25 records I want to 
delete.  
> > But when I click on ! I get "cannot delete from specified tables."
> > 
> > 
> > What am I doing wrong?
> > 
Message #2 by "Richard Lobel" <richard@a...> on Thu, 25 Jul 2002 14:07:21 -0700
Brian,
You don't have to craft an SQL statement to do this. The best way is to
set up a relationship in the relationships window. When you create it,
enforce Referential Integrity and check Cascade Delete Related Records.
Then when you delete the record in the one table, all related records in
the many (or other one) tables will automatically be deleted. Be careful
though, because you won't want to always have this happen.

Richard Lobel
President
NoClassroom.com
Live Software training 
Right over the Internet 
richard@n...
Tel:  (xxx) xxx-xxxx
Fax:  (xxx) xxx-xxxx

*****ORIGINAL MESSAGE*****

Say you have mulitple tables. Table1, 
Table2, and Table3. Table1 contains a Primary Key and tables 2&3 have a 
field related to that key. How would you craft an SQL statement to
delete 
all records either of tables 2&3 that have a corresponding record in 
Table1?



  Return to Index