Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Server restart problem

Author  Topic 

rockshire
Starting Member

3 Posts

Posted - 2008-04-07 : 06:31:43
Hi,

I've got a table with a column that contains the status of available licenses to the user, i.e. they are either in use or are available. If the server goes down, then when it is restarted I need to make sure all the rows in this column describe each license as being available.

So the question is how can I ensure data in a table is, if you like, initialized, each time the server is restarted? Is there a system defined stored proc or trigger than is executed when a server is restarted?

Thanks.

tprupsis
Yak Posting Veteran

88 Posts

Posted - 2008-04-07 : 14:09:48
Every time SQL Server is started, tempdb is recreated and populated based on the model db. So you could do it by creating a table in the model database that has all your license status information. Then read/write from the table in tempdb as normal. Only problem with this method is that your license table will be copied to any new database created on the server.
Go to Top of Page

rockshire
Starting Member

3 Posts

Posted - 2008-04-08 : 04:05:52
Thanks for your reply. Your answer gave me an idea. If the tempdb is recreated each time the server starts, then maybe I could use a DDL trigger to fire when a new database is created. If the database being created is tempdb, I could interpret this as a server restart perhaps?

Having said this, I would have thought there would be an easier way. It must be a common scenario to want to update some data in a table when a server is restarted.........
Go to Top of Page

tprupsis
Yak Posting Veteran

88 Posts

Posted - 2008-04-08 : 11:32:16
I thought the same thing about the DDL trigger. Before posting yesterday I tested that out. I didn't see the trigger fire but maybe I was doing something wrong. Let me know if you have any better luck with that than I did.
Go to Top of Page

rockshire
Starting Member

3 Posts

Posted - 2008-04-08 : 11:34:58
Hi,

I've relasied that the easiest way to do this is use automatic execution of a stored procedure on startup.

See http://msdn2.microsoft.com/en-us/library/ms191129.aspx for details......
Go to Top of Page
   

- Advertisement -