473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SQL 2005 : AFTER INSERT - Trigger

Is it possible to create a trigger in one database, that after an
insert, will update a database on a different server?

If so, how would I do this?

Thanks.

Bill

Jun 7 '07 #1
1 6539
Stout (st*****@gmail.com) writes:
Is it possible to create a trigger in one database, that after an
insert, will update a database on a different server?
Yes, this is possible. Whether it is really a good idea is another
matter. Triggers execute in the context of a transaction, and an access
to a linked server may not be that fast. Thus, this can have impact on
concurrency, which depending on the application may matter a lot, or not
at all.
If so, how would I do this?
The trigger code as such, is not difficult:

CREATE TRIGGER remote_tri FOR INSERT ON tbl AS
UPDATE SERVER.db.dbo.remotedbl
SET col = i.someval
FROM SERVER.db.dbo.remotedbl r
JOIN inserted i ON r.keycol = i.keycol

The inserted table is a virtual table that holds the newly inserted rows.
(Note plural: a trigger fires once per statement.)

What may be a hassle, is to get everything to work with the distributed
transaction. Keep in mind here that if the update on the remote server
fails, the INSERT must be rolled back. And if local server goes belly-up
before the INSERT is committed, then the operation on the remote server
must also be rolled back. MS DTC handles these low-level parts, but
still some stars have to be aligned. DTC must be running on both servers.
And if the machines run different versions of the operating system
there can be more problems.

One thing you need to ask yourself is how tightly connected the operation
on the remote server has to be on the local server. Maybe something
more loosely coupled like replication is to prefer? Or if you are on
SQL 2005, could Service Broker be a better solution.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 7 '07 #2

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

Similar topics

4
by: DTB | last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to replicate a BEFORE UPDATE trigger from ORACLE. Here is a sample of the ORACLE BEFORE UPDATE trigger: CREATE TRIGGER myTRIGGER ON...
2
by: 73blazer | last post by:
Perhaps my thinking is wrong but this is what I have: 1 table (Tab1) with 1 attribute (Attr1) Attr1 char(16) for bit data ----------------------------------------------- create trigger...
2
by: R.A.M. | last post by:
Hello, I am learning SQL Server 2005. I need to create a trigger which increments number of book's publications: CREATE TRIGGER InsertPublication ON Publications AFTER INSERT AS BEGIN
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
1
by: filip1150 | last post by:
I'm trying to find if there is any performance diference between explicitly using a sequence in the insert statement to generate values for a column and doing this in an insert trigger. I...
0
by: sheenaa | last post by:
Hi Everyone, I m using ASP.NET 2005 with C# and SQL SERVER 2005. I m using stored procedure and sql datasource control to retrieve the data. I want to use the trigger...
1
by: Zeljko Bilandzija | last post by:
Hello! I have a problem, and I looking for help if someone can handle this. I use asp.net 2.0, and I create web site which support users from internet (Web Site Administration Tool) and with...
1
by: veasnamuch | last post by:
I have a problem while I create a trigger to my table. My objective is getting any change made to my table and record it in to another table . My have thousands records before I add new trigger to...
2
by: gimme_this_gimme_that | last post by:
I'm using DB2 8.1. Suppose table foo has columns name and lname: create table foo (name as varchar(200), lname as varchar(200)); Write a trigger that inserts the lower case value of name...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.