Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « SQLCop is now available via chocolateyYou should be watching »
    comments

    You know that you can mark a proc to run at startup in SQL Server. What you have to do is create the stored procedure in the master database and after that you have to set the startup flag to true. If your stored procedure name is spMyProc, the code would look like this.

    1. exec sp_procoption N'spMyProc', 'startup', 'on'

    What if you want to list all the stored procedures on your server which are set to run on startup? Here is how you do this

    1. SELECT name,create_date,modify_date
    2. FROM sys.procedures
    3. WHERE OBJECTPROPERTY(OBJECT_ID, 'ExecIsStartup') = 1

    That query will give you the name, creation date and modification date of every stored procedure that is set to run on startup.

    Aaron Bertrand pointed out that you can also use the is_auto_executed column, here is what the query would look like now, much easier to read

    1. SELECT name,create_date,modify_date
    2. FROM sys.procedures
    3. WHERE is_auto_executed = 1

    Creating stored procedures to run on startup is a nice way of ensuring that certain flags/tables/users are created/updated/deleted when the SQL instance is restarted, this way you won't forget to run that code that you have tucked away in some folder that needs to be run to initialize some data on startup.

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    393 views
    Instapaper

    2 comments

    Comment from: Aaron Bertrand [Visitor] · http://sqlblog.com/blogs/aaron_bertrand/
    Aaron Bertrand Why use objectproperty() when there is already a column in sys.procedures for this? Not that it's a performance concern I just find column references easier to read than nested built-in function calls...
    11/15/11 @ 10:26
    Comment from: SQLDenis [Member] Email
    SQLDenis Thanks Aaron, I added the query you suggested also
    11/15/11 @ 10:42

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)