• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 642
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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