View Full Version : SQL to clear multiple Tables


kriemer
09-13-2005, 08:54 PM
I am currently using this Query to delete all records in Table x:
Delete * From x;

Then repeating similar for Table y, then Table z, etc


I would like to delete all records from multiple Tables in a single step, e.g.:
DELETE x.*, y.*, z*
FROM x, y, z;

I get an error message "could not delete from specified tables". Could anyone tell me where where I am going wrong?

Thanks

k

arobbo
09-14-2005, 12:02 PM
are any of the tables linked ?

maybe its the order they are being deleted in

RV
09-14-2005, 12:05 PM
I would like to delete all records from multiple Tables in a single step, e.g.:
DELETE x.*, y.*, z*
FROM x, y, z;
k

You can't.
You need to follow your original approach.

RV

Pat Hartman
09-14-2005, 10:27 PM
If the tables are related in a hierarchial manor such as Orders - OrderDetails, when you delete an order, you want to delete all related detail items, you need to define their relationship using the relationship window, select the enforce referential integrity box and then check the cascade delete box.

If the tables are unrelated, you must run three separate queries. If you want to automate the task, create a form with a button and let the code in the click event of the button run the queries or create a macro (I don't recommend macros).

kriemer
09-15-2005, 03:54 AM
Wonderful, wonderful, wonderful!!!