SQL Not Auto-incrementing

auto-increment, sql, sql-server, t-sql

Solution

you need to specify its seed and increment.( plus , i dont think there is `integer` keyword ....)

id  [int] IDENTITY(1,1) NOT NULL,

the first value is the seed

the second one is the delta between increases

A Question you might ask :

delta between increases ? why do i need that ? its always 1 ....??

well - yes and no. sometimes you want to leave a gap between rows - so you can later insert rows between... specially if its clustered index by that key....and speed is important... so you can pre-design it to leave gaps.

p.s. ill be glad to hear other scenarios from watchers.

Problem

I have the following SQL I trigger in a C# app. All works well but the ID table doesn't auto increment. It creates the value of 1 for the first entry then will not allow other inserts due to not being able to create a unquie ID. Here is the SQL: ``` CREATE TABLE of_mapplist_raw ( id integer PRIMARY KEY NOT NULL, form_name varchar(200) NOT NULL, form_revi varchar(200) NOT NULL, source_map varchar(200), page_num varchar(200) NOT NULL, fid varchar(200) NOT NULL, fdesc varchar(200) NOT NULL )"; ``` I'm sure its a schoolboy error at play here.

Original source