• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

SQL Server 2008: Table trigger to insert in external database

Hello,


I want to make a trigger on a table in my internal database (SQL Server 2008) that executes a stored procedure on an external database(SQL Server 2005) when a row is inserted with a certain value.

Database 1 - Table A
 > When a row is inserted AND the value of Field A is 1 then the trigger is fired
 > The trigger executes a stored procedure on an External database

How do i do this ?
 - How can i link the two servers ? Do i have to adapt security settings ?
 - How do i have to built the trigger ?


kind regrads
0
Xyleen
Asked:
Xyleen
1 Solution
 
MikeWalshCommented:
Well first off I would say be careful of such solutions. Triggers are really meant to be a place to do something quick. The time to execute the trigger is part of the time for the underlying operation to complete. So if the trigger takes awhile because of the complex stored procedure on the other database, the code in the trigger to determine if the proc should be called or not, etc. then your underlying user will be affected. If that stored proc has an error or runs on, then your transaction will be left hanging. I would look at other solutions to get this info.. Maybe ETL on a regular basis, maybe code in the application or the stored proc that asynchrounously dumps the data.

That being said, how?

Look up create trigger in books online. Pay attention to the parts about the inserted virtual table. Remember multiple rows could be inserted so code a set based solution.

To link, I like limited rights and named connections for linked servers. Helps with trobleshhoting. Link with a specific account with just the necessary rights. Create the linked server on server A. look up linked server in books online for the various options.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now