O'Reilly logo

What's New in SQL Server 2012 by Jon Reade, Rachel Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

SEQUENCE

You are no doubt used to IDENTITY and how this works with a seed and increment value. SEQUENCE is structured in a very similar way, but with fewr limitations, giving it a welcome flexibility.

A SEQUENCE object is created at the database level but, unlike an IDENTITY property, it can be used across multiple tables. An IDENTITY value is generated when you insert a row into a table and it cannot be updated. You can retrieve the SEQUENCE value at any time and reset it without altering its previous value, and even set a minimum and maximum value. Let us look at a simple example:

CREATE SEQUENCE mySequence AS int
START WITH 1
INCREMENT BY 1

As you can see, mySequence is now available for use by all tables in the database:

We have not used the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required