• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

Accessing the id of updated record in update trigger

Hi

In an update trigger, how do you access the record ID of the record that has just been updated and hence triggered the trigger :)

andrea
0
andieje
Asked:
andieje
1 Solution
 
hongjunCommented:
try
    select id from inserted
0
 
andiejeAuthor Commented:
Hi
I've seen this solution which mentions Insert tables on the server
http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21951149.html

but I don't know what these are and how to find them

thanks
andrea
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the INSERTED and DELETED tables are virtual tables that are accessible ONLY withing the trigger code, and are available to you without any additional work/code.
just use them in the trigger as "normal" tables in regards to queries, note that when multiple records are update at once, the tables will contain multiple rows also.
0
 
dbrckoviCommented:

ALTER  TRIGGER [TrigUpdate] ON [dbo].[aaa]
FOR INSERT, UPDATE, DELETE
AS

select Inserted.[ID] as [Last ID] FROM Inserted
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now