473,500 Members | 1,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing which data caused a trigger to fire

Hi.

I need to make a trigger which fires when after an UPDATE is done on
table A in database X. The trigger must perform a statement which
copies some of the data from the update to table B in database Y on
the same server.
My question is: Can I access the data which caused the trigger to fire
or just get an indication of which entry in table A had been updated?

Best Regards
Jens Christian Andersen.

Feb 28 '07 #1
2 2974
There are 2 pseudo-tables available in trigger code: "deleted" and
"inserted". When a trigger is fired by an UPDATE statement, the "deleted"
table contains images of the rows before the update and the "inserted" table
contain the row images after the update. In your update trigger code, you
can do something like:

INSERT INTO Y.dbo.B (Column1, Column2)
SELECT Column1, Column2
FROM inserted

In a trigger fired by a DELETE statement, the "deleted" table contains the
rows just deleted and the "inserted" table is empty. Similarly, when a
trigger is fired by an INSERT statement, the "inserted" table contains the
rows just inserted and the "deleted" table in empty. See the Books Online
for details.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"jcandersen" <jc*@dse.dkwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
Hi.

I need to make a trigger which fires when after an UPDATE is done on
table A in database X. The trigger must perform a statement which
copies some of the data from the update to table B in database Y on
the same server.
My question is: Can I access the data which caused the trigger to fire
or just get an indication of which entry in table A had been updated?

Best Regards
Jens Christian Andersen.
Feb 28 '07 #2
On 28 Feb., 14:07, "Dan Guzman" <guzma...@nospam-online.sbcglobal.net>
wrote:
There are 2 pseudo-tables available in trigger code: "deleted" and
"inserted". When a trigger is fired by an UPDATE statement, the "deleted"
table contains images of the rows before the update and the "inserted" table
contain the row images after the update. In your update trigger code, you
can do something like:

INSERT INTO Y.dbo.B (Column1, Column2)
SELECT Column1, Column2
FROM inserted

In a trigger fired by a DELETE statement, the "deleted" table contains the
rows just deleted and the "inserted" table is empty. Similarly, when a
trigger is fired by an INSERT statement, the "inserted" table contains the
rows just inserted and the "deleted" table in empty. See the Books Online
for details.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"jcandersen" <j...@dse.dkwrote in message

news:11**********************@8g2000cwh.googlegrou ps.com...
Hi.
I need to make a trigger which fires when after an UPDATE is done on
table A in database X. The trigger must perform a statement which
copies some of the data from the update to table B in database Y on
the same server.
My question is: Can I access the data which caused the trigger to fire
or just get an indication of which entry in table A had been updated?
Best Regards
Jens Christian Andersen.
Thanks, this is just what I needed.

Mar 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3510
by: Neil Rutherford | last post by:
During testing of an application, i noticed a difference between SQL 2000 and SQL 7, both with identical config. In a nutshell: A table has a trigger for UPDATE and DELETE. When a column in the...
10
2023
by: heromull | last post by:
We have an asp.net app with about 200 data entry forms. Customers may enter data into any number of forms. Each form's data is persisted in a corresponding sql table. When data entry is...
3
3412
by: Ricardo Corsi | last post by:
Hi, It is possible to call a trigger (inside a sql server..) with asp.net ? how can i do that ? thks!
8
2600
by: Frank van Vugt | last post by:
Hi, If during a transaction a number of deferred triggers are fired, what will be their execution order upon the commit? Will they be executed in order of firing or alfabetically or...
2
9992
by: Dima Gofman | last post by:
I have a trigger on UPDATE on a table. I'm running some maintenance UPDATE and DELETE queries which I want the trigger to ignore but at the same time I want other UPDATE queries that other users...
1
2869
by: aj70000 | last post by:
hi, Here's the scenario 1) I am running a DTS job to fetch some rows from Oracle 2) The job populates the Table A as step 1 3) Then it fires a update statement which updates the rows in Table...
4
2327
by: Alexis | last post by:
Hello, I'm facing oracle trigger problem. Anyone can help or advise how to resolve it? Below are the explaination on my problem I've created a trigger for my program. When there is a new...
2
4060
by: Parnamwulan | last post by:
Hello guys, Pls dont laugh - it is not funny (actually it is, but it is causing me problems) I have problem with SQLDA data type specification. I need to create some counted columns, so I...
7
6364
by: srkidd12 | last post by:
Hello, Does anyone know how to get a trigger to fire while you are uploading multiple records into a SQL Server 2005 Express DB using the DTS Wizard? On insert of a person's record I want the...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.