Sequences are new feature in SQL Server Denali
Those who are aware with Oracle/Postgres are aware with sequence. However better late than never 🙂
MS has added sequence in Deanli
This can help us to solve many problems we are facing with Identity and programmer will have more control on DB.Sequences are not bounded to tables and they are controlled by applications.
Lets see with Example for it
Definition from BOL
CREATE SEQUENCE [schema_name . ] sequence_name
[ AS [ built_in_integer_type | user-defined_integer_type ] ]
[ START WITH ]
[ INCREMENT BY ]
[ { MINVALUE [ ] } | { NO MINVALUE } ]
[ { MAXVALUE [ ] } | { NO MAXVALUE } ]
[ CYCLE | { NO CYCLE } ]
[ { CACHE [ ] } | { NO CACHE } ]
[ ; ]
A sequence can be defined as any Intger Type
Bigint is a default option
START WITH
The first value from where the sequence starts. The value must be constant
INCREMENT BY
The increment value for the sequence. The value must be constant
MINVALUE
Minvalue for the sequence
MAXVALUE
Maxvalue for the sequence
CYCLE
The sequence should restart when it reaches maxvalue
Cycle will restart from minvalue/maxvalue not from start value
Lets see with an Example for this
lets cycle the sequence with range of values
Here you can see the seuqence has range from1 to 3 and after than it restarts with 1.