Is it possible to delete from multiple tables in the same SQL statement?

后端 未结 5 1495
自闭症患者
自闭症患者 2020-11-27 07:10

It\'s possible to delete using join statements to qualify the set to be deleted, such as the following:

DELETE J
FROM Users U
inner join LinkingTable J on U.         


        
5条回答
  •  萌比男神i
    2020-11-27 07:46

    Use TRY CATCH with Transaction

    BEGIN TRANSACTION
    BEGIN TRY
        DELETE from A WHERE id=1
    
        DELETE FROM b WHERE id=1
    
        COMMIT TRANSACTION;
    END TRY
    BEGIN CATCH
    ROLLBACK TRANSACTION;
    END CATCH
    

    or you can also use Store procedure for same Using Stored Procedure With Transaction:

提交回复
热议问题