Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update constraint on multiple fields
Message
 
 
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:
01275432
Vues:
8
>>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)
>>IF EXISTS ( SELECT * FROM inserted i JOIN DELETED d ON d.pk = i.pk 
				WHERE d.fk_engine <> i.fk_engine 
					OR d.fk_stage <> i.fk_stage 
					OR d.fk_part <> i.fk_part)


>>
>>
>
>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.

Combining yours and Sergey's idea it would be:
 if exists (select * from Traveler where fk_product = deleted.PK) and 
  EXISTS ( SELECT * FROM inserted i JOIN DELETED d ON d.pk = i.pk 
				WHERE d.fk_engine <> i.fk_engine 
					OR d.fk_stage <> i.fk_stage 
					OR d.fk_part <> i.fk_part)

  begin
    Print ...
    Print ....
    rollback 
  end
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