any pitfalls of cross-database triggers?

  • I want to use the Microsoft aspnetdb to control membership/profile/login etc. However some items in another database (on the same server) must be associated with a userID

    I could run a job periodically to get new userIDs into the 2nd database, or I could write an AFTER INSERT trigger to maintain a copy of aspnet_Membership in the 2nd database.

    I prefer the trigger idea - I'm just asking for a sanity check here.

  • if the second table (the one maintained by the trigger) is involved in a a lot of transactions then the trigger might be a bad idea. In that case use some form of replication.

    If its basically a read only table then the trigger idea should be okay.

    The probability of survival is inversely proportional to the angle of arrival.

  • if the databases are on the same server, you could just reference the table directly in the other database by using the three-part naming convention

    database.owner.table

  • I would recommend any option that does not involve triggers. Triggers fire within the scope of the transaction so using a trigger to populate a table in another database would mean that the transaction would be held open for each INSERT until the subsequent INSERT into the second DB happens. It's just not a good idea.

    I would vote for replication of that table, or defining a view in your second database that used a linked server to get the data from the first table.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • If you have any concern for disaster recovery, you'll also want to keep in mind that cross-database transactions are not supported in Database Mirroring or Availability Groups...

    https://msdn.microsoft.com/en-us/ms366279

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply