Nordine
Nordine

Reputation: 866

Script for updating sequences with SQL Server

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

Upvotes: 1

Views: 111

Answers (1)

Ken Keenan
Ken Keenan

Reputation: 10558

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'

Upvotes: 5

Related Questions