Deleting Records in Joined Multiple Tables in a DataBase
How can I delete a particular record in a DataBase where 6 tables are join开发者_如何学运维ed among each other.
It is possible to create the FOREIGN KEY (with "ON DELETE CASCADE" action) Constraint(s) that will automatically remove records from the corresponding referenced tables. Take a look at the “FOREIGN KEY Constraints” Books Online / MSDN topic for more information.
Do it within a transaction. Referential integrity isn't checked until the transaction is closed:
begin;
delete from table1 where ...;
delete from table2 where ...;
delete from table3 where ...;
commit;
精彩评论