Solved

SQL Server Return rowId after update Trigger

Posted on 2009-04-09
6
986 Views
Last Modified: 2012-05-06
Hey SQL Experts

I need help creating a "on Update Trigger "for a given table  . Is it possible to return the Primary key rowID of a row in my Customer table.
I do not have access to the ASPx page that invokes the table update.
Example: if Customer's phone number has changed, I want to know the ROWID for this customer so that I may update a related table.
0
Comment
Question by:scubamikey
  • 3
  • 2
6 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 20 total points
Comment Utility
in the trigger, you have the full row data in the INSERTED table, which includes the primary key field.
can you clarify what you are missing, actually?
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 230 total points
Comment Utility
This is a bad way to do what you're needing, but here goes (note that this will return multiple records if > 1 is updated)

create trigger triggername on tablename
after update
as
begin
select primarykeyfield
from inserted  --inserted is the actual name, you don't need to change this.
end
0
 

Author Comment

by:scubamikey
Comment Utility
Thanks, Is the INSERTED estblished for a ROW that has been Updated??
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 60

Accepted Solution

by:
chapmandew earned 230 total points
Comment Utility
the inserted table is almost like a temporary table that gets created as a result of the update.  In this case, the inserted table contains an exact replica of the structure of the table that was update, and contains the newest values (the newly updated values).  There is also a deleted table that you could use that would be exactly like the inserted table (rows, structure, etc), but it contains the OLD values (the values before the update).  So, if you updated 5 rows, the inserted would have 5 rows w/ the new values, the deleted table would have 5 rows w/ the old values.
0
 

Author Closing Comment

by:scubamikey
Comment Utility
I Did not now that Thanks
0
 

Author Comment

by:scubamikey
Comment Utility
know that..
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now