Owner: | Sales |
Table/View: | Sales.Store |
Disabled: | |
Encrypted: | |
Creation Date: | 04/26/2006 |
Modification Date: | 04/26/2006 |
Description: | AFTER INSERT trigger inserting Store only if the Customer does not exist in the Individual table. |
QUOTED_IDENTIFIER: | |
ANSI_NULLS: |
Instead of: | |
Insert: | |
Update: | |
Delete: |
Objects that [Sales].[iStore] depends on
Object Name | Owner | Object Type | Dep Level | |
Flag | dbo | User Defined type | 1 | |
Name | dbo | User Defined type | 1 | |
NameStyle | dbo | User Defined type | 1 | |
Phone | dbo | User Defined type | 1 | |
ufnLeadingZeros | dbo | Function | 2 | |
Contact | Person | Table | 2 | |
ErrorLog | dbo | Table | 2 | |
SalesTerritory | Sales | Table | 2 | |
uspPrintError | dbo | Procedure | 2 | |
Customer | Sales | Table | 3 | |
Employee | HumanResources | Table | 3 | |
uspLogError | dbo | Procedure | 3 | |
Individual | Sales | Table | 4 | |
SalesPerson | Sales | Table | 4 | |
Store | Sales | Table | 5 |
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
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
-- Only allow the Customer to be a Store OR Individual
IF EXISTS (SELECT * FROM inserted INNER JOIN [Sales].[Individual]
ON inserted.[CustomerID] = [Sales].[Individual].[CustomerID])
BEGIN
-- Rollback any active or uncommittable transactions
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
END;
END TRY
BEGIN CATCH
EXECUTE [dbo].[uspPrintError];
-- Rollback any active or uncommittable transactions before
-- inserting information in the ErrorLog
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION;
END
EXECUTE [dbo].[uspLogError];
END CATCH;
END;
GO
SET QUOTED_IDENTIFIER OFF
GO
GO
SET ANSI_NULLS OFF
GO
See Also
List of triggers