Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update constraint on multiple fields
Message
 
 
À
12/12/2007 14:29:52
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:
01275278
Vues:
6
This message has been marked as a message which has helped to the initial question of the thread.
>But what is the logic... Would something like this work?
>
>
>CREATE TRIGGER CheckPK ON [Product]
>FOR UPDATE
>AS
>DECLARE @countFk int
>SELECT @countFk = SELECT count(fk_product) from Traveler where fk_product = insert.pk)
>
>IF @countFk > 0
>	AND (fk_engine != insert.fk_engine
>	OR fk_stage != insert.fk_stage
>	OR fk_part != insert.fk_part)
>BEGIN
>PRINT ‘Cannot change Products that have dependents’
>PRINT ‘Transaction has been cancelled’
>ROLLBACK
>END
>
>
Margaret,

I think you should check the previous value (e.g. from deleted) and then may be your logic against inserted table, though I'm not sure what exactly you're checking.

In other words, it should check
SELECT @countFk = SELECT count(fk_product) from Traveler where fk_product = deleted.pk)
and then act accordingly. Also do you want to check if you changed fk_engine, etc. fields? If yes, then join deleted with inserted tables based on the PK.
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform