Solved

SQL Server Return rowId after update Trigger

Posted on 2009-04-09
6
989 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
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

23 Experts available now in Live!

Get 1:1 Help Now