Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't create sequence in SQL Server 2008

I have tried to create a sequence in SQL Server 2008 using the following query,

CREATE SEQUENCE serial START 100

I got the following syntax error,

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'SEQUENCE'.

How to create a sequence in SQL Server 2008?

like image 558
Karthik Avatar asked Aug 30 '11 04:08

Karthik


People also ask

How do I create a sequence in SQL Server?

The syntax to a view the properties of a sequence in SQL Server (Transact-SQL) is: SELECT * FROM sys. sequences WHERE name = 'sequence_name'; sequence_name.

How do you create a sequence for an existing table?

CREATE SEQUENCE rid_seq; ALTER TABLE test ADD COLUMN rid INTEGER; ALTER TABLE test ALTER COLUMN rid SET DEFAULT nextval('rid_seq');

What is cache in sequence in SQL?

The cache is maintained in memory by tracking the current value (the last value issued) and the number of values left in the cache. Therefore, the amount of memory used by the cache is always two instances of the data type of the sequence object.


1 Answers

You just cannot do this.

SQL Server 2008 does not have the concept of a SEQUENCE - this is a new feature in SQL Server 2012 (MSDN documentation here).

Typically, you want to create an "auto-increasing" column for your table - in that case, use the IDENTITY column attribute instead:

CREATE TABLE dbo.YourTable
( TableID INT IDENTITY,
 .....
like image 107
marc_s Avatar answered Sep 24 '22 14:09

marc_s