﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Run a Query on a Database Restore / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 10:40:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Run a Query on a Database Restore</title><link>http://www.sqlservercentral.com/Forums/Topic1391613-391-1.aspx</link><description>Much better than my approach. I keep forgetting to check Extended Events for solutions to problems like these. Thanks for posting Lowell.</description><pubDate>Mon, 03 Dec 2012 07:04:39 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: Run a Query on a Database Restore</title><link>http://www.sqlservercentral.com/Forums/Topic1391613-391-1.aspx</link><description>I'm sure you have to use extended events, specifically on the [b]AUDIT_BACKUP_RESTORE_EVENT[/b]I did something as a prototype that did a few things on my dev server;if you restored a database, then it added roles if they did not exist, and another one that looked for and fixed orphaned users.so when a database gets restored a stored procedure gets executed with my desired code, with references to the database in question.this article By Jonathan Kehayias, 2009/12/22 was my starting point that i added code to.[b][url]http://www.sqlservercentral.com/articles/Event+Notifications/68831/[/url][/b]</description><pubDate>Mon, 03 Dec 2012 06:55:27 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>RE: Run a Query on a Database Restore</title><link>http://www.sqlservercentral.com/Forums/Topic1391613-391-1.aspx</link><description>Can you just build the query into the process that does the restore?If not, you'll need to have a T-SQL statement with a TRY/CATCH that you can run, probably on a schedule from SQL Agent. Then, if it can USE the database, it runs the query, if not, it errors out until next time. Not sophisticated, but it will probably work.</description><pubDate>Mon, 03 Dec 2012 05:43:22 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>Run a Query on a Database Restore</title><link>http://www.sqlservercentral.com/Forums/Topic1391613-391-1.aspx</link><description>Hi,I'm looking for how I can have a query run against a database when it is restored. Basically, I have multiple copies of the same db structure with some default data that when restored, I would like to run some queries to adjust configuration. There must be a way to setup a trigger to run a Stored Procedure or a set query but I am having trouble finding documentation.Can anyone point me in the right direction?Thanks in advance!</description><pubDate>Fri, 30 Nov 2012 18:33:33 GMT</pubDate><dc:creator>lisa_stlaurent</dc:creator></item></channel></rss>