0
我將如何把這個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語句一個try/catch存儲過程?
爲什麼?您希望通過在交易中包裝單個聲明來完成什麼?單個語句是原子的 - 要麼是成功的,要麼添加行,要麼失敗,表保持不變。你看了[文檔](https://docs.microsoft.com/en-us/sql/t-sql/language-elements/try-catch-transact-sql)嗎?並嘗試[Erland的討論](http://www.sommarskog.se/error_handling/Part1.html),在這一點上可能會有點過分。 – SMor