Auto increment primary key in SQL Server Management Studio 2012(SQL Server Management Studio 2012 中的自动增量主键)
问题描述
我如何auto increment
primary key
在SQL Server
数据库表中,我看过论坛但可以不知道如何.
How do I auto increment
the primary key
in a SQL Server
database table, I've had a look through the forum but can't see how.
我查看了属性但看不到选项,我看到了一个答案,您可以转到 Identity
规范属性并将其设置为 yes 并设置 Identity将
增加到 1,但该部分是灰色的,我无法将 no 更改为 yes.
I've looked the the properties but can't see an option, I have seen an answer where you go to the Identity
specification property and set it to yes and set the Identity increment
to 1, but that section is grayed out and I can't change the no to yes.
一定有一种简单的方法可以做到这一点,但我找不到.
There must be a simple way to do this but I can't find it.
推荐答案
确保Key列的数据类型为int
,然后手动设置identity,如图
Make sure that the Key column's datatype is int
and then setting identity manually, as image shows
或者运行这段代码
-- ID is the name of the [to be] identity column
ALTER TABLE [yourTable] DROP COLUMN ID
ALTER TABLE [yourTable] ADD ID INT IDENTITY(1,1)
代码将运行,如果 ID
不是表中唯一的列
the code will run, if ID
is not the only column in the table
图像参考先进先出
这篇关于SQL Server Management Studio 2012 中的自动增量主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server Management Studio 2012 中的自动增量主键


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01