您的位置:首页 > 产品设计 > UI/UE

Summary on 20080701: insert value for identity column in sql

2008-07-02 21:39 441 查看
In MSSQLServer, by default, user can‘t insert/assign/update value for identity column; SQLServer will do this for user automatically, so there is one problem caused that: what will do if  wants to assign value for identity column? for one table like: teacher(teacher_id, teacher_name, teacher_age), and teacher_id is identity the insert should be like: insert into teacher values('kalash',12), that's correct format, if insert is like: insert into teacher values(1,'kalash',12), there will be error when execute the statement

and for the case that user want to insert value for identity column, user can turn on the identity_insert for implicitly insert, the code is as followed:


for the above code, please note that: 1. for the insert, the column name should be listed out, especially the 'teacher_id' 2. any time, the 'identity_insert' can be set to 'on' for only one table, if the 'identity_insert' is set to 'on' and set that for another table, there will be error, so for tip3 3. it's suggested that every time after set the identity_insert to be 'on', set it back to 'off' after the operation
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  insert sqlserver table user sql
相关文章推荐