Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 R2. Incorrect syntax near 'AUTO_INCREMENT'

Why do i get the following error

Incorrect syntax near 'AUTO_INCREMENT'.

while trying to execute

CREATE TABLE Person
(
    P_Id int NOT NULL AUTO_INCREMENT,
    Name varchar(255),

    PRIMARY KEY (P_Id)
)

What is the correct syntax?

like image 487
OrElse Avatar asked May 06 '11 10:05

OrElse


1 Answers

CREATE TABLE Person(
P_Id int NOT NULL IDENTITY(1,1) PRIMARY KEY,
Name varchar(255))

You should explicitly state whether NAME is NULL or NOT NULL so you are not dependant upon the current connection settings that happen to be in effect.

like image 50
Martin Smith Avatar answered Oct 03 '22 02:10

Martin Smith