BEGIN TRANSACTION
BEGIN TRY
DECLARE @NewCategoryID INT
INSERT INTO Production.ProductCategory( NAME )
VALUES ( 'Widgets' )
SET @NewCategoryID = SCOPE_IDENTITY()
INSERT INTO Production.ProductSubcategory(ProductCategoryID, NAME )
VALUES (@NewCategoryID, 'Super Widgets' )
--DELETE FROM Production.ProductCategory
--WHERE ProductCategoryID = 1
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
PRINT ERROR_MESSAGE()
PRINT ERROR_NUMBER()
PRINT ERROR_LINE()
END CATCH
SELECT *
FROM Production.ProductCategory