HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Why do MS SQL Server SEQUENCEs not have an ORDER parameter like Oracle?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
whyordersqllikeparameterserveroraclenotsequenceshave

Problem

In the documentation of CREATE SEQUENCE for T-SQL, you can see that the CREATE SEQUENCE command has no ORDER parameter.

For comparison, the Oracle docs for CREATE SEQUENCE show the ORDER/NOORDER options:

ORDER


Specify ORDER to guarantee that sequence numbers are
generated in order of request. This clause is useful if you are using
the sequence numbers as timestamps. Guaranteeing order is usually not
important for sequences used to generate primary keys.


ORDER is necessary only to guarantee ordered generation if you are
using Oracle Database with Real Application Clusters. If you are using
exclusive mode, sequence numbers are always generated in order.

NOORDER


Specify NOORDER if you do not want to guarantee sequence
numbers are generated in order of request. This is the default.

Does Microsoft SQL Server provide a strong ordering constraint for SEQUENCEs? Or does Microsoft not consider it important in general?

Solution

In SQL Server all the sequence numbers are generated on a single instance so they are already inherently ordered. And if you’re just using them as unique numbers it shouldn’t really matter anyway.

The Oracle implementation is different because in a RAC environment (not all Oracle implementations), two sequence numbers could be generated by two different “instances” (that’s the wrong term for Oracle but just drawing equivalency in SQL Server). Normally you wouldn’t care if the one requested first was slower and got a higher number than the one requested later - unless, as the Oracle docs say, you were using the sequences as timestamps to truly reflect the order of the original request.

Context

StackExchange Database Administrators Q#244408, answer score: 12

Revisions (0)

No revisions yet.