Recently when presenting my Extended Event session at a SQL Saturday an attendee asked if the Create Database session I used as a demo would pick up the Tempdb that is recreated at start up. The answer is that it will not. But this question got me thinking, what about a restore or attaching a database, would the event pick that up?
I have to admit, while I suspected that it would not pick up the TempDB creation, I was not 100% certain on whether or not the Create Database event fires on start up. So I wanted to do a quick test and the answer is that the event does not fire when the SQL Server service is restarted.
What about when a database is attached? When attaching a database, this event does indeed fire. Which of course makes sense, at least to me, you are creating a new database when attaching the database files.
What about when a database is restored? Although a restore is in reality a drop and recreate the database, it does NOT fire the Create Database event. I tried both restoring the database with the same name and a different name and neither one was picked up by the Create Database event.
Thanks for visiting my blog!!!