No, SEQUENCE cannot be schema bound in SQL Server. Schema binding is supported only for views and functions, and SQL Server does not allow NEXT VALUE FOR inside schema-bound objects. SEQUENCE is nondeterministic and state-changing, so SQL Server prevents schema binding to avoid unintended number generation, dependency locks, and unpredictable execution behavior.
See the demo.
Creating sequence
|
CREATE SEQUENCE TestSeq_Schemademmo START WITH 1 INCREMENT BY 1; GO |
Now we are creating a view with SCHEMABINDING
let’s see
|
CREATE VIEW Vw_ Schemademo WITH SCHEMABINDING AS SELECT NEXT VALUE FOR TestSeq_Schemademo AS Num; |
Creating now
Even without schemabinding, SQL
Server does not allow NEXT VALUE FOR in a view at all.
Let’s see with function
Creating a function with SCHEMABINDING
|
CREATE FUNCTION dbo.Schemademo() RETURNS BIGINT WITH SCHEMABINDING AS BEGIN RETURN NEXT VALUE FOR
TestSeq_Schemademo; END |
Creating now.
So schema binding is impossible
here too.