Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update constraint on multiple fields
Message
 
 
À
13/12/2007 11:21:02
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01275199
Message ID:
01275529
Vues:
8
>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
>
>
You don't need two extra counters, that was my point. You may use EXISTS the same way. E.g. if (exists (select fk from Table1 t inner join deleted on t.fk = d.PK) or ...) and ...
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform