小标
2018-07-06
来源 :
阅读 3137
评论 0
摘要:本文主要向大家介绍了SQLServer数据库自增字段插入值的步骤,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
本文主要向大家介绍了SQLServer数据库自增字段插入值的步骤,通过具体的内容向大家展现,希望对大家学习SQLServer数据库有所帮助。
我们今天主要与大家一起分享的是SQL Server数据库之向SQL Server自增字段中插入值的正确操作步骤,以及对其实际操作中要用到的实际操作代码的描述,以下就是文章的详细内容的具体描述。
通常情况下,不能向 SQL Server 自增字段插入值,如果非要这么干的话,SQL Server 就会好不客气地给你个错误警告:
1. Server: Msg 544, Level 16, State 1, Line 1
2. Cannot insert explicit value for identity column in table 't' when identity_insert is set to OFF.
这个错误消息提示我们,如果向 SQL Server 自增字段插入值,需要设置 identity_insert 选项为 on。
1. set identity_insert on
看具体的一个例子:
1. create table dbo.t
2. (
3. id int identity(1,1) not null,
4. name varchar(50)
5. )
6. set identity_insert t on
7. insert into t (id, name) values(1, 'sqlstudy')
8. set identity_insert t off
注意的是,自增字段插入值后,要及时把 identity_insert 设置为 off。
本文由职坐标整理并发布,希望对同学们学习SQL Server有所帮助,更多内容请关注职坐标数据库SQL Server数据库频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号