Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update constraint on multiple fields
Message
From
13/12/2007 11:21:02
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01275199
Message ID:
01275522
Views:
10
There was one modification in the way the pk was being checked. A select had to be used to match the deleted.pk. Below is the actual trigger. Margaret.
CREATE TRIGGER CK_Product_update ON [Product]
FOR UPDATE
AS
DECLARE @countFk int, @countTrans int
SELECT @countFk = count(TRAVELER.fk_product) 
        from Traveler where fk_product IN
	(SELECT PK FROM DELETED)

SELECT @countTrans = count(fk_product) 
        from Trans_sernum where fk_product IN
	(SELECT PK FROM DELETED)

IF (@countFk > 0 or @countTrans > 0)
    and EXISTS ( SELECT * FROM inserted i JOIN 
    DELETED d ON d.pk = i.pk 
    WHERE d.fk_engine <> i.fk_engine 
    OR d.fk_assembly <> i.fk_assembly
    OR d.fk_basematerial <> i.fk_basematerial				
    OR d.fk_parttype <> i.fk_parttype 
    or d.hpt <> i.hpt
    or d.stage <> i.stage)

    BEGIN
        PRINT 'Cannot change Products that have dependents'
        PRINT 'Transaction has been cancelled'
        ROLLBACK
    END
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform