本文介绍了如何从三个表中删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个与聚会相关的表.如何删除这些记录.
请给我建议
谢谢与问候
venkatesh
I have three tables which are related togather.How should I delete those records.
pls give me suggestions
Thanks & regards
venkatesh
推荐答案
--We're deleting from multiple tables, so trans control
BEGIN TRANSACTION
--Lowest level first, attempt to delete the order quantities
DELETE FROM order_quantities WHERE oq_catalogue_id_fk IN (SELECT ocd_id_pk FROM order_catalogue_details WHERE ocd_order_id_fk = @OrderID)
IF (@@Error !=0)
BEGIN
ROLLBACK TRANSACTION
RETURN @@ERROR
END
--Now delete all the catalogue items for the order
DELETE FROM order_catalogue_details WHERE ocd_order_id_fk = @OrderID
IF (@@Error !=0)
BEGIN
ROLLBACK TRANSACTION
RETURN @@ERROR
END
--remove the main order information
DELETE FROM orders WHERE ord_id_pk = @OrderID
IF (@@Error !=0)
BEGIN
ROLLBACK TRANSACTION
RETURN @@ERROR
END
COMMIT TRANSACTION
这篇关于如何从三个表中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!