如何使用单个查询将我的值插入身份和非身份字段 [英] How to insert my values to identity and non identity field using single query

查看:43
本文介绍了如何使用单个查询将我的值插入身份和非身份字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用方案SET IDENTITY_INSERT数据插入数据(名字,姓氏,数量,rollno)值(``yLMdxMRqUuwCWQMzfXeqhdymQDOaiBKSvYLUBigGHLfYHKwof'',``hEezSvnAnUYRgsKDhYeSXWINS'',``74''关闭

这是我的问题:

这里是在列中的字段中随机插入字符串和整数.
像这样,如果整数字段是Identity(自动递增)则插入整数表示此查询非常完美

但是该字段不是身份(自动递增),这意味着它不起作用,我无法执行set operation nu报错...所以我想为身份和非身份字段都插入整数该怎么办?

如果我要插入标识字段,则要打开和关闭执行设置操作
非标识字段,无需执行设置操作

如何在单个查询中同时使用两者?如何修改我的查询?

有人说为身份和非身份字段动态传递Iinserting)整数的正确查询吗?

use regimen SET IDENTITY_INSERT data ON insert into data (firstname,lastname,quantity,rollno) values (''yLMdxMRqUuwCWQMzfXeqhdymQDOaiBKSvYLUBigGHLfYHKwof'',''hEezSvnAnUYRgsKDhYeSXWQxJwXz'',''858437.74'',''98834'') SET IDENTITY_INSERT data OFF

Hi this is my problem:

Here am randomly inserting strings and integer to the fields in the column.
like that while am inseting integer if the integer field is Identity(auto increment)]mean this query works perfect

but the fiels is not an identity(auto increment) mean it not work i got error not able to perform set opertation nu...so i want to insert integer for both Identity and non identity fields how to do that?

if i wantto insert identity field want to perform set operation on and off
non identity field no need to perform set operation

how to use both work in single query?how to modify my query?

anybody say the correct query for dynamically passingIinserting) integer for an identity and non identity fields?

推荐答案

您正在尝试关闭身份.如果您不知道您的字段是否是身份字段,那么您真的对数据库不了解太多,无法对其进行更新.如果您要定期更改身份字段,为什么还要使用身份字段?您想做什么?
You''re trying to turn off identity. If you don''t know if your fields are identity fields or not, then you really don''t know enough about the DB to be updating it. Why have identity fields if you''re going to routinely change them ? What are you trying to do ?


这篇关于如何使用单个查询将我的值插入身份和非身份字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆