SQL 创建语句在自动增量附近的语法不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15049434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:52:55  来源:igfitidea点击:

SQL create statement incorrect syntax near auto increment

sqlsql-server

提问by sharon Hwk

I created the following table, but I get an error;

我创建了下表,但出现错误;

Incorrect syntax near 'AUTO_INCREMENT'.

“AUTO_INCREMENT”附近的语法不正确。

SQL

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?

我想我已经做对了一切。有人可以帮我吗?

回答by Mahmoud Gamal

It is IDENTITYnot AUTO_INCREMENTin SQL Server.

IDENTITY不在AUTO_INCREMENTSQL 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)
);

回答by spajce

Its not AUTO_INCREMENT. Here the Demofrom sqlfiddle

它不是AUTO_INCREMENT。这里是来自 sqlfiddle的Demo