question

JD avatar image
JD asked

Secuence-like type fields in MSSQL

Hi everyone, Yesterday I wsa solving a problem in a PosgressSQL database and I found a secuence, is some type of object that create a secuence and can be use as defaul value for a field, so, this fiels should behive like the autonumeric field and can be use as unique key. My cuestion is, is any like this in MSSQL..?
uniquekey
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image
Fatherjack answered
To have an automatically generated and incremented column value in a table you can use an INT column and set it as an IDENTITY. `CREATE TABLE Test (aColumn INT IDENTITY (1,1))` will mean that any row inserted into this table will have a new value, one more than the value of last row inserted. the (1,1) controls where the numbering starts and how big the gaps between numbers are - (10,2) would have numbering start at 10 and new rows would be every 2nd number. There are lots of caveats when using this property of a column, you should read all about it at http://msdn.microsoft.com/en-us/library/ms186775.aspx
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JD avatar image JD commented ·
Thanks..!, I'm reviewing now the MSDN and I find some interesting things to slove gaps problems that can occurs when deleting rows
0 Likes 0 ·
ThomasRushton avatar image
ThomasRushton answered
As well as the IDENTITY field in SQL Server, in the next version (Denali), there's also the "SEQUENCE". See MS's documentation at , and there are various blog articles about it including one that I wrote... The main benefit of this is that you can use the same sequence of IDs across multiple tables.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.