?
Solved

SQL Server Return rowId after update Trigger

Posted on 2009-04-09
6
Medium Priority
?
1,006 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 80 total points
ID: 24107375
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 920 total points
ID: 24107387
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
ID: 24107456
Thanks, Is the INSERTED estblished for a ROW that has been Updated??
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 60

Accepted Solution

by:
chapmandew earned 920 total points
ID: 24107493
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
ID: 31568539
I Did not now that Thanks
0
 

Author Comment

by:scubamikey
ID: 24107548
know that..
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

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