简体   繁体   English

如何在 TSQL/SQL Server Express 中创建列 AUTOINC?

[英]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.

相关问题 我如何在没有TSQL的SQL Server 2008上执行此查询 - How can I do this Query on SQL Server 2008 without TSQL 如何在tsql中将2行转换为列? - How can I convert 2 row into column in tsql? 我可以在SQL Server / TSQL中回滚动态SQL吗? - Can I rollback Dynamic SQL in SQL Server / TSQL 在SQL Server中,如何对实例中的所有数据库执行一段tsql? - In SQL Server, how can I execute a piece of tsql against all databases in an instance? 如何在 SQL Server 中使用 TSQL 命令跟踪存储过程的修改? - How can I trace out modification of stored procedure with TSQL Command in SQL Server? 如何将我的数据库上的所有sql server管理工作室激活作为可执行的tsql日志? - How can i get all my sql server managment studio activite on my database as a executable tsql log? 在SQL Server中,如何将大量的tsql语句分成批处理? - In SQL Server, how can I separate a large number of tsql statement into batches? 如何使用 tsql 获取 sql 服务器实例中的所有数据库名称? - How can I get all the database names in a sql server instance using tsql? 如何在SQL Server中创建一个接受数据列的函数? - How do I make a function in SQL Server that accepts a column of data? 使用 SQL/TSQL,如何在此 WHILE 子句中使用 STUFF? - With SQL/TSQL, how can I use STUFF within this WHILE clause?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM