新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
SQLServer自增字段插入值的實(shí)際操作
在實(shí)際操作中我們經(jīng)常會(huì)遇到向SQL Server自增字段插入值的這一狀況,以下的文章主要向大家描述的是向SQL Server自增字段插入值的實(shí)際操作步驟,在一般的情況下,不能直接向 SQL Server 數(shù)據(jù)庫(kù)的自增字段插入值。

如果非要這么干的話,SQL Server 就會(huì)好不客氣地給你個(gè)錯(cuò)誤警告:
- Server: Msg 544, Level 16, State 1, Line 1
- Cannot insert explicit value for identity column in table 't' when identity_insert is set to OFF.
這個(gè)錯(cuò)誤消息提示我們,如果向 SQL Server 自增字段插入值,需要設(shè)置 identity_insert 選項(xiàng)為 on。
- set identity_insert on
看具體的一個(gè)例子:
- create table dbo.t
- (
- id int identity(1,1) not null,
- name varchar(50)
- )
- set identity_insert t on
- insert into t (id, name) values(1, 'sqlstudy')
- set identity_insert t off
注意的是,自增字段插入值后,要及時(shí)把 identity_insert 設(shè)置為 off。
上述的相關(guān)內(nèi)容就是對(duì)SQL Server自增字段插入值的描述,希望會(huì)給你帶來一些幫助在此方面。
以上的相關(guān)內(nèi)容就是對(duì)SQL Server自增字段插入值的介紹,望你能有所收獲。
當(dāng)前名稱:SQLServer自增字段插入值的實(shí)際操作
網(wǎng)站網(wǎng)址:http://www.5511xx.com/article/cdghico.html


咨詢
建站咨詢
