如何将此SQL Server语句
USE OnlineStore
GO
CREATE PROC dbo.spInsertNewProduct
AS
BEGIN
INSERT INTO Product (Name, Size, SalePrice, Category, Department, Location, Description, ProductCondition, SKU, Colors, LastOrderDate, InventoryQuantity, AverageRating)
VALUES ('King Arthur: Legend of the Sword (Blu-Ray)',
'5 3/8” wide x 6 3/4” tall and 1/2” thick', 24.99,
'Blu-Ray', 'Movies', 'Ontario',
'Blu-Ray of King Arthur: Legend of the Sword', 'New', '324510',
'Blue', '2017-8-3', 17, 86)
END在使用事务的try/catch中?
发布于 2017-08-07 19:41:20
正如SMor在评论中建议的那样,对于插入来说,这样做没有任何意义,它要么进入,要么不进入,所以实际上,没有什么可以回滚的。但是,如果您希望实现一个try/catch,则syntax将为:
USE OnlineStore
GO
CREATE PROC dbo.spInsertNewProduct
AS
BEGIN
BEGIN TRY
BEGIN TRAN
INSERT INTO Product (Name, Size, SalePrice, Category, Department, Location, [Description], ProductCondition, SKU, Colors, LastOrderDate, InventoryQuantity, AverageRating)
VALUES ('King Arthur: Legend of the Sword (Blu-Ray)',
'5 3/8” wide x 6 3/4” tall and 1/2” thick', 24.99,
'Blu-Ray', 'Movies', 'Ontario',
'Blu-Ray of King Arthur: Legend of the Sword', 'New', '324510',
'Blue', '2017-8-3', 17, 86)
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
END CATCH
ENDhttps://stackoverflow.com/questions/45537294
复制相似问题