Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any feedback on my first SQL Server trigger
Message
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Any feedback on my first SQL Server trigger
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01096860
Message ID:
01096860
Views:
65
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
Next
Reply
Map
View

Click here to load this message in the networking platform