Solved

SQL Server Return rowId after update Trigger

Posted on 2009-04-09
6
995 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 20 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 230 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 60

Accepted Solution

by:
chapmandew earned 230 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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