Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any feedback on my first SQL Server trigger
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Any feedback on my first SQL Server trigger
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01096860
Message ID:
01096860
Vues:
63
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform