Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get Triggering Row?
Message
From
11/10/2002 13:08:58
 
 
General information
Forum:
Microsoft SQL Server
Category:
Database design
Miscellaneous
Thread ID:
00710415
Message ID:
00710431
Views:
17
This message has been marked as the solution to the initial question of the thread.
SQL Server triggers fire once regardless of the number of rows involved in the command. It will fire once for one row, five rows, or zero rows. Please keep this in mind. All triggers must be capable of handling multiple rows or throwing and error if multiple rows are affected.

Within a trigger, SQL Server will create two tables in memory: Inserted and Deleted. The Inserted table will contain a copy of the rows after the data modifiecation has occurred. The Deleted table will contain a copy of the rows before the data modification has occurred.

Your query would probably look like:

UPDATE Reports
SET Reports.ReportCreatedDate = getdate()
Where reports.id in (
select id from inserted)

-Mike

>Given a painfully simple trigger as follows: How do you get the row firing the trigger for the where clause? RowThatCausedTheTriggerToFire is an elusive prey beast.... :)
>
>CREATE TRIGGER PutDate ON dbo.Reports
>after INSERT
>AS
>UPDATE Reports
>SET Reports.ReportCreatedDate = getdate()
>Where {RowThatCausedTheTriggerToFire}
>
>
>My Humble thanks in advance,
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform