Automatically execute script once database has been attached

  • Hi there - our clients have the flexibility to detach and attach databases (I know there are a lot of considerations around this but there is now way of changing it), once they attach a database we need to run some code to update a bunch of values in the database.

    Other than creating a SQL Agent job are there any other options available to automatically execute a script once the database has been attached?

    Thanks all!

    --------------------------------------------

    Laughing in the face of contention...

  • Offhand, I'd suggest trying a DDL trigger on the CREATE DATABASE event (note that attaching fires 'CREATE DATABASE ... FOR ATTACH'), and see if that catches it.

    If so, you can call whatever code you like when it occurs.

    Link to Books Online topic:

    https://msdn.microsoft.com/en-us/library/ms190989%28v=sql.100%29.aspx

    -Eddie

    Eddie Wuerch
    MCM: SQL

Viewing 2 posts - 1 through 1 (of 1 total)

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