How to make an id field in SQL Server?(如何在 SQL Server 中创建 id 字段?)
问题描述
我想创建一个字段,该字段将自动填充并保持唯一性.
I want to make a field, which will be automatically filled, and stay unique.
更多说明:我有一个ID字段,应该由我的程序而不是用户填写,是我的主键.
More explanation: I have an ID field, which should be filled by my program not the user, and is my primary key.
如何在 SQL Server 中执行此操作?
How may I do it in SQL Server?
我使用的是 Visual Studio 2010
I'm using Visual Studio 2010
推荐答案
在您的 ID 列中,将身份"设置为是"并将种子"设置为 1.
On your ID column, set "identity" to yes and set the "seed" to 1.
享受吧!
这篇关于如何在 SQL Server 中创建 id 字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 SQL Server 中创建 id 字段?
基础教程推荐
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
