0

I'm having trouble using the ALTER SEQUENCE statement in SQL Server.

This is the code I'm using:

ALTER SEQUENCE MakatiORSeries RESTART WITH 23;

And this is what I'm getting:

Msg 15151, Level 16, State 1, Line 7
Cannot alter the sequence 'MakatiORSeries', because it does not exist or you do not have permission.

But when I select all the sequences from sys.sequences, it is there

SELECT * 
FROM sys.sequences 
WHERE [name] = 'MakatiORSeries'

I tried these references too:

SQL Server sequence set current value

Use a variable or parameter to specify restart value for ALTER SEQUENCE

Any help is greatly appreciated. Thanks!

4
  • 3
    is the account you using have the permission? because you need certain level of permission to alter sequences. Commented Nov 18, 2020 at 4:23
  • im not really sure, how do i know these permissions? Commented Nov 18, 2020 at 6:07
  • I'm not really sure how to access those info in sql-server but try fn_my_permissions here is the msdn link : msdn Commented Nov 18, 2020 at 6:34
  • update: i just found out that if i try to add that ALTER code into an existing stored procedure in my project, it is working, but then when I call that stored proc in my solution, exception is thrown with that same error message Commented Nov 18, 2020 at 7:14

2 Answers 2

0

The ALTER permission on the sequence or the schema is required to change this. Ownership chaining in a procedure allows basic DML such as INSERT, UPDATE, DELETE, SELECT, and EXECUTE. It does not extend to ALTER. The account that runs the procedure will also need the ALTER permission on the sequence.

If there are permissions that can't be granted to the login because of security concerns, then you can sign the procedure to run as another credential.

Sign up to request clarification or add additional context in comments.

4 Comments

oh this makes why i cant run the solution, but in sql server itself it runs, that means the user im using in my solution has no permission right? Thanks!
question, can I use update script instead of ALTER when setting the current value of sequence number?
You have to use ALTER. You are changing the object, not updating a record. Create a database role (e.g., AppRole) for the application and add the required user to this role. Grant the role the alter right on the sequence. The GUI can be used. Or perhaps GRANT ALTER ON OBJECT::dbo.MakatiORSeries TO [AppRole] is easier than the GUI.
thank you very much! this helped me a lot as i was confused what to do
-1

If you want to restart the sequence to set it to a specific value use

SELECT setval('seq',0,false);

It sets the value of the sequence "seq" to 0.

1 Comment

does not work. Err msg ['setval' is not a recognized built-in function name.]

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.