SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

Create TRIGGER [dbo].[AccFactor_CheckDelete]
ON [dbo].[AccFactor] INSTEAD OF DELETE 
	AS
		DECLARE @TaxUID as UNIQUEIDENTIFIER
		DECLARE @ID as bigint
		select @TaxUID=TaxUID, @ID=ID from Deleted
		if @TaxUID = CAST(0x0 AS UNIQUEIDENTIFIER) 
		BEGIN
			delete From dbo.AccFactor where id=@ID
		END
		else
		    RAISERROR('امکان حذف فاکتور ارسال شده به سامانه نیست.',16,20) WITH LOG, SETERROR
	return