1

I'm using Microsoft SQL Server 2008 R2 for a JEE Application (JSF, JPA, EclipseLink).

I restart my database weekly and doing that I need to update the sequence of all my tables like that:

UPDATE[dbo].[SEQUENCE] 
SET [SEQ_COUNT] = (SELECT MAX(IDAGENCE) 
                   FROM AGENCE) 
WHERE SEQ_NAME = 'SEQ_AGENCE'

My question is: how do I trigger a script when I restart my database to update all my sequences?

Thanks you for your help

1
  • 1
    Haven't tried it myself, but take a look at this blog post - it was the first thing to show up when I Googled for this. Commented Dec 20, 2016 at 8:49

1 Answer 1

5

There is a built-in stored procedure in SQL Server, sp_procoption, that lets you designate a stored procedure to run when the server restarts. You would use it like this:

EXEC sp_procoption @ProcName = 'MyProcedure', @OptionName = 'STARTUP', @OptionValue = 'ON'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.