SQL Server 2012 developing a new feature sequence object (Sequence)

Source: Internet
Author: User

Reprint Link: http://www.cnblogs.com/zhangyoushugz/archive/2012/11/09/2762720.html

As we all know, in the previous version of SQL Server, the GUID or identity is generally used as the identifier, but the identity is a table object, can only guarantee the sequence in a table, when we encounter the following situations,

Table 1

Id Order type Price
1 Train tickets 200
4 Plane ticket 2000
5 Tickets 600

Table 2

Id Order type Price
2 Hotel 400
3 Park tickets 170
6 Rental fee 300

For example, we need to implement ID consistency between multiple tables, and in SQL Server there will be some trouble, usually we will use an extra temp table to map the relationship of these IDs and then take the sequence from it.

Sequence is very early in Oracle, and SQL Server 2012 's sequence function is similar to that of a schema-based object, so it can be called by multiple tables.

The sequence syntax is as follows:

  1. CREATE SEQUENCE [schema_name.] Sequence_name
  2. [As [Built_in_integer_type | user-defined_integer_type]]
  3. [START with <constant>]
  4. [INCREMENT by <constant>]
  5. [{MINVALUE [ <constant>]} | {NO MINVALUE}]
  6. [{MAXVALUE [ <constant>]} | {NO MAXVALUE}]
  7. [CYCLE | {NO CYCLE}]
  8. [{CACHE [ <constant>]} | {NO CACHE}]
  9. [ ; ]
CREATE SEQUENCE [schema_name.] Sequence_name    [as [Built_in_integer_type | user-defined_integer_type]]    [STAR T with <constant>]    [INCREMENT by <constant>]    [{MINVALUE [<constant>]} | {NO MINVALUE}]    [{MAXVALUE [<constant>]} | {NO MAXVALUE}]    [CYCLE | {NO CYCLE}]    [{CACHE [<constant>]} | {NO CACHE}]    [ ; ]

Start with Set start value

Increment by setting the growth interval

Min and Max set minimum and maximum values respectively

Cycle setting is loop

cache specifies settings for caching

SQL Server 2012 developing a new feature sequence object (Sequence) (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.