AdventureWorks
iStore Trigger
Description
AFTER INSERT trigger inserting Store only if the Customer does not exist in the Individual table.
Properties
Creation Date08/01/2010 08:41
Encrypted
Ansi Nulls
Trigger Type
Insert Delete Update After Instead Of
Trigger Definition
CREATE TRIGGER [Sales].[iStore] ON [Sales].[Store] 
AFTER INSERT AS 

BEGIN
DECLARE @Count int;
SET @Count = @@ROWCOUNT;
IF @Count = 0 
RETURN;
SET NOCOUNT ON;
BEGIN TRY
IF EXISTS (SELECT * FROM inserted INNER JOIN [Sales].[Individual] 
ON inserted.[CustomerID] = [Sales].[Individual].[CustomerID]) 
BEGIN
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END;
See Also

Related Objects

Sales.Store Table
Sales Schema
AdventureWorks Database

 

 


© 2012 All Rights Reserved.

Send comments on this topic.