Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger one table to another db.table Quetsion

Status
Not open for further replies.

dpwsmw

MIS
Apr 2, 2003
76
US
I have a situation, I want to create an Insert trigger, I have 2 tables they are Identical one is in db1.ar1_cust and the other is in db2.ar1_cust I want a trigger that when something changes in one, it will change in the other. I was wondering if there was like a Wildcard that you could put in that would insert all the new info, since the tables are Identical.
 
If both databases are on the same server it's pretty easy to do.

You use three-part naming.

In your INSERT trigger you would have a statement something like:
INSERT INTO db2.dbo.ar1_cust SELECT * FROM inserted. This assumes there is no possibility of a primary key conflict. 'inserted' is the virtual table that holds the update or insert results.

If the databases are on different servers, and you have the correct permissions between them, you can use four-part naming like server.database.owner.table
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top