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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SQL please 1

Status
Not open for further replies.

ishfady

Programmer
Sep 14, 2002
31
GB
Hi

I have access 2003 database, which is running fine.

I have two table Staff and StaffAddress. At the moment there is no contrain and data in StaffAddress gone bed. I want to put constrain on this two tables ie 1-to-many from Staff to StaffAddress. But it doesn.t allow me to do that. Because there are records in table StaffAddress, which has no related record in Staff table. So I want to delete them.

Is there any way I can just delete record from StaffAddress which has no link in staff.

Please could help me and provide sql for it.

Many thank
 
delete from StaffAddress where staffAddress.PrimaryKey IN( select staff.ForeignKey from staff);

assuming you have the keys of both tables set up properly...

p.s. you don't really need to have rigid relationships setup between tables, it's only when you want to do cascade delete/updates that these are required.

Procrastinate Now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top