新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQLServer數(shù)據(jù)庫自增字段正確的插入值的描述
我們今天主要向大家講述的是SQL Server數(shù)據(jù)庫之向SQL Server自增字段正確的插入值的實(shí)際操作步驟,在一般的情況下,我們不能向 SQL Server 數(shù)據(jù)庫自增字段中插入值,如果非要這么干的話,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ù)據(jù)庫自增字段插入值,需要設(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數(shù)據(jù)庫之向SQL Server自增字段插入值的描述,希望會(huì)給你帶來一些幫助在此方面。
【編輯推薦】
- MS SQL Server 連接字符串的實(shí)際操作簡介
- SQL Server 字符串在實(shí)際操作中的注意事項(xiàng)
- SQL Server 連接字符串的一些聲明
- 鏈接SQL Server數(shù)據(jù)庫中的字符串經(jīng)驗(yàn)總結(jié)
- SQL Server 連接字符串的實(shí)現(xiàn)步驟
分享標(biāo)題:SQLServer數(shù)據(jù)庫自增字段正確的插入值的描述
當(dāng)前路徑:http://www.dlmjj.cn/article/dpdodco.html


咨詢
建站咨詢
