-3

On SQL Server, I'm trying to alter sequence on a remote server using this:

ALTER SEQUENCE SeverName.DbName.sys.SeqName_sequence RESTART WITH 1000;

Unfortunately, this does not work. Does anyone know if this is possible and the correct syntax?

Charlieface
  • 52,284
  • 6
  • 19
  • 43
Pat Hall
  • 9
  • 1
  • 1
    And the error is ...? If you look at the documentation, you will see that you can only alter a sequence in the current database - only a two-part name (schema.sequence) is allowed. Connect directly to the instance and database and run your alter script there. – SMor Aug 23 '22 at 16:22

1 Answers1

2

You can do this using dynamic SQL, and specify that database's sp_executesql procedure.

DECLARE @sql nvarchar(max) = '
ALTER SEQUENCE SomeSchemaName.SomeSequenceName RESTART WITH 1000;
';

EXEC SeverName.DbName.sys.sp_executesql @sql;
Charlieface
  • 52,284
  • 6
  • 19
  • 43