Использование транзакций с перехватом исключений
Использование транзакций с перехватом исключений
CREATE TABLE [dbo].[Books2]
(
N int PRIMARY KEY NOT NULL,
Name nchar(10) NULL,
New bit NULL
) ON [PRIMARY]
BEGIN TRANSACTION
BEGIN TRY
INSERT INTO Books2 (N, New, Name) VALUES (1, 1, 'Book1')
SAVE TRANSACTION savepoint1
INSERT INTO Books2 (N, New, Name) VALUES (2, 1, 'Book2')
INSERT INTO Books2 (N, New, Name) VALUES (3, 'one', 'Book3')
END TRY
BEGIN CATCH
PRINT 'Error!'
ROLLBACK TRANSACTION savepoint1
END CATCH
COMMIT TRANSACTION
SELECT *
FROM [dbo].[Books2]
|