# Trigger: dVendor

## Properties

Property | Value
--- | ---
Trigger | dVendor
ID | 1723153184
Owner | dbo
Schema | Purchasing
For Object | Vendor
Disabled |
Is Not For Replication |
Trigger Type Description | SQL TRIGGER
ANSI NULLS |
QUOTED IDENTIFIER |
Encrypted |
MS Shipped |
Execute As | Caller
Modify Date | 8/8/2010 5:23:44 PM
Creation Date | 8/8/2010 5:23:44 PM

## Extended Properties

Name | Value
--- | ---
MS_Description | INSTEAD OF DELETE trigger which keeps Vendors from being deleted.

## Trigger Type

Is After Trigger | Is Instead Of | Insert Trigger | Update Trigger | Delete Trigger
--- | --- | --- | --- | ---

## First / Last Trigger

First Delete Trigger | First Insert Trigger | First Update Trigger | Last Delete Trigger | Last Insert Trigger | Last Update Trigger
--- | --- | --- | --- | --- | ---

## Objects that depend on [dVendor]

- dVendor

## Objects on which [dVendor] depends

- dVendor
  - Purchasing.Vendor
    - dbo.uspLogError
      - dbo.uspPrintError
      - dbo.ErrorLog
    - dbo.Flag
    - dbo.Name
    - dbo.AccountNumber
    - Person.BusinessEntity

## SQL

Script
SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE TRIGGER [Purchasing].[dVendor] ON [Purchasing].[Vendor] INSTEAD OF DELETE NOT FOR REPLICATION AS BEGIN DECLARE @Count int; SET @Count = @@ROWCOUNT; IF @Count = 0 RETURN; SET NOCOUNT ON; BEGIN TRY DECLARE @DeleteCount int; SELECT @DeleteCount = COUNT(*) FROM deleted; IF @DeleteCount > 0 BEGIN RAISERROR (N'Vendors cannot be deleted. They can only be marked as not active.', -- Message 10, -- Severity. 1); -- State. 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; EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'INSTEAD OF DELETE trigger which keeps Vendors from being deleted.' , @level0type=N'SCHEMA',@level0name=N'Purchasing', @level1type=N'TABLE',@level1name=N'Vendor', @level2type=N'TRIGGER',@level2name=N'dVendor'

#### See also

List of Triggers