본문 바로가기

Database/MS-SQL

SQL @@Error 그리고 TRANSACTION BEGIN TRAN ROLBACK COMMIT IF ELSE문 사용 예

반응형
BEGIN TRANSACTION
INSERT INTO Order VALUES(@ID, @ CustomerID , @OrderDate) 
IF(@@Error = 0 ) BEGIN INSERT INTO LineItem VALUES (@ItemID, @ID, @ProductID , @Price)
       IF(@@Error = 0) COMMIT TRANSACTION ELSE ROLLBACK TRANSACTION END 
ELSE ROLBACK TRANSACTION END