Thursday, 21 April 2011

Execute a stored procedure on SQLServer Startup

For a project we needed to run some T-SQL scripts when the SQL Express Database Engines on the client machines started (we need to have data available offline).
To get the job done,  SQL Server has the possibility to execute a stored procedure at it's startup.

For this you will need to execute:

1: sp_procoption  @ProcName  =  'stored procedure name',  
2:               @OptionName  =  'startup',  
3:               @OptionValue  = 'on'  
4: 

To turn it off again: 
1: sp_procoption  @ProcName  =  'stored procedure name',  
2:               @OptionName  =  'startup',  
3:               @OptionValue  = 'off'  
4: 


To see which procedures will be executed at startup:

1: SELECT  Name  
2: FROM  sysobjects   
3: WHERE  objectproperty(id, 'ExecIsStartup' )  =  1
4: 

Have fun
J.

No comments:

Post a Comment