SQL create statement incorrect syntax near auto increment

Its not AUTO_INCREMENT. Here the Demo from sqlfiddle


It is IDENTITY not AUTO_INCREMENT in SQL Server.

Try this instead:

CREATE TABLE [dbo].[MY_TABLE] (
    [ID] INT NOT NULL IDENTITY(1, 1),
    [NAME]          NVARCHAR (100) NULL,
    [SCHOOL]             NVARCHAR (100) NULL,
    PRIMARY KEY (ID)
);

Use IDENTITY for MSSQL as shown below. *AUTO_INCREMENT is for MySQL and MariaDB:

CREATE TABLE [dbo].[MY_TABLE] (
    [ID] INT NOT NULL IDENTITY, -- Here
    ...
);

In addition, you can have a custom IDENTITY with "()" as shown below. The 1st argument is for start value and the 2nd argument is for increment value so in the example below, if first inserting a row, ID is 20 and if second inserting a row, ID is 23, then ID is 26, 29, 32...:

                               -- Increment value
CREATE TABLE [dbo].[MY_TABLE] (--  ↓
    [ID] INT NOT NULL IDENTITY(20, 3),
    ...                     --  ↑
);                          -- Start value   

And, IDENTITY is equivalent to IDENTITY(1, 1).

Tags:

Sql

Sql Server