How can I run some SQL code every time SQL Server starts?

A. With SQL 6.x use the sp_markstartup supplied stored-procedure. This will run any SP you write yourself as soon as SQL Server finishes initialising.

With SQL 7.0 the same result is achieved using sp_procoption to mark the SP for auto-start. Another way, assuming that you use SQL Agent, is to define a SQL Agent job with the 'Start automatically when the SQLServerAgent starts' option. However, this will run the job every time SQL Agent is re-started (if it ever is).


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish