T-SQL - Insert Multi rows with BEGIN TRANSACTION, COMMIT TRANSACTION, ROLLBACK TRANSACTION, Save Error Log to TABEL
BEGIN
BEGIN TRY
BEGIN TRANSACTION
INSERT INTO Students VALUES('Sothea', 'Male')
INSERT INTO Score VALUES((SELECT MAX(StuId) FROM Students), 'S1', '25'),((SELECT MAX(StuId) FROM Students), 'S2', '40')
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
INSERT INTO Error_Log VALUES(GETDATE(), ERROR_SEVERITY(), ERROR_MESSAGE())
END CATCH
END
T-SQL - Insert Multi rows with BEGIN TRANSACTION, COMMIT TRANSACTION, ROLLBACK TRANSACTION, Save Error Log to TABEL
Reviewed by Unknown
on
7:30 PM
Rating:
No comments: