In order to execute a Stored Procedure when SQL Server starts, you first need to enable scanning for Startup Procedures with the following code:
EXEC sys.sp_configure N'scan for startup procs', N'1'GORECONFIGURE WITH OVERRIDEGO
Once you have configured your server to run Stored Procedures on startup, you have to enable the desired Stored Procedure to run at startup:
USE masterGOEXEC SP_PROCOPTION ProcToRunAtEachStartup, 'STARTUP', 'ON'GO
Now, each time your server is started the above stored procedure (named ProcToRunAtEachStartup – you can name yours anything you like) will run.
Related Articles
- Obtain the Oldest Open Transaction
- Access Previous Row Value and Next Row Value
- How to Check for a NULL Value and an Empty String
Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.























