[英]How can I make a column AUTOINC in TSQL / SQL Server Express?
The Server Explorer Table creation facility automatically adds an Id column to each Table you create:服务器资源管理器表创建工具会自动向您创建的每个表添加一个 Id 列:
But I noticed that, although it is indeed set as a PRIMARY KEY, it does not specify that it is an AutoInc column.但是我注意到,虽然它确实设置为 PRIMARY KEY,但它并没有指定它是 AutoInc 列。
So I added that directly to the T-SQL tab, but that is considered a syntax error:所以我直接将其添加到 T-SQL 选项卡中,但这被认为是语法错误:
Is it already an auto-inc, and I don't need to specify it as such, or if I do need to, what am I doing wrong?它是否已经是一家汽车公司,我不需要这样指定它,或者如果我确实需要,我做错了什么?
In SQL Server, it's not an AUTO_INCREMENT, it's an identity:在 SQL Server 中,它不是 AUTO_INCREMENT,而是一个标识:
CREATE TABLE dbo.Genres
(
[GenreId] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Genre] VARCHAR(20) NULL
);
https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver15 https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver15
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.