Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any feedback on my first SQL Server trigger
Message
De
16/02/2006 15:25:38
Mike Yearwood
Toronto, Ontario, Canada
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01096860
Message ID:
01096867
Vues:
12
Only thing I'd add is

REPLACE repmod with DATE() IN Dept

>I'm converting an app from VFP to SQL Server 2005 and I've just had a stab at converting my first trigger. Any comments on the code I used. The purpose of the trigger is to update a field with the current date, if 1 of 2 fields have changed.
>
>VFP Function called by the record validation event.
>
>
>FUNCTION dept_rv()
>	
>	SELECT dept
>	IF 	dept.repdate <> oldval("repdate","dept") OR ;
>		dept.repstaff <> oldval("repstaff","dept")
>		REPLACE dept.repmod WITH date()
>	ENDIF
>
>	RETURN .T.
>ENDFUNC
>
>SQL Server Update Trigger
>
>
>set ANSI_NULLS ON
>set QUOTED_IDENTIFIER ON
>go
>
>ALTER TRIGGER [Trigger_Dept_Update] on [dbo].[dept] AFTER UPDATE AS
>    IF UPDATE(repdate) or UPDATE(repstaff)
>		BEGIN
>			UPDATE Dept SET repmod = GETDATE() FROM Dept INNER JOIN inserted ON dept.id = inserted.id
>		END
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform