SQL Server 2008: Table trigger to insert in external database

Posted on 2009-12-24
Last Modified: 2012-05-08

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
Question by:Xyleen
    1 Comment
    LVL 13

    Accepted Solution

    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.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 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

    17 Experts available now in Live!

    Get 1:1 Help Now