Search code examples
sqlsql-serverdatabaseauto-incrementsql-server-identity

SQL create statement incorrect syntax near auto increment


I created the following table, but I got the error below;

Incorrect syntax near 'AUTO_INCREMENT'.

SQL:

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

I think I have done everything right. Can someone help me out?


Solution

  • 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)
    );