Search code examples
sqldatabaseauto-increment

AUTO_INCREMENT doesn't work in SQL server 2012?


CREATE TABLE detectives(
    id INTEGER NOT NULL AUTO_INCREMENT,
    first_name VARCHAR(50),
    last_name VARCHAR(50) NOT NULL,
    phone_number VARCHAR(10) NOT NULL,
    certification_date DATE NOT NULL,
    CONSTRAINT detectives_pk PRIMARY KEY (id
);

It says: Incorrect syntax near 'AUTO_INCREMENT'.

Any help with this?


Solution

  • Missing closing ) and using incorrect syntax for an IDENTITY field.

    CREATE TABLE detectives(
        id INT IDENTITY,
        first_name VARCHAR(50),
        last_name VARCHAR(50) NOT NULL,
        phone_number VARCHAR(10) NOT NULL,
        certification_date DATE NOT NULL,
        CONSTRAINT detectives_pk PRIMARY KEY (id)
        )