无法为标识列插入显式值

编程入门 行业动态 更新时间:2024-10-25 06:32:40
本文介绍了无法为标识列插入显式值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当IDENTITY_INSERT设置为OFF时,无法在表'Producto'中为identity列插入显式值。 alter proc uspIdatos_ @iDProducto int output, @Descripcion nvarchar(50), @Precio money, @Stock int, @Notas text as 插入到Producto(IDProducto,Descripcion,Precio,Stock,Notas)值(@ iDProducto,@ Descripcion,@ Precio,@ Stock,@ Notas) SET @iDProducto = @@ IDENTITY

Cannot insert explicit value for identity column in table 'Producto' when IDENTITY_INSERT is set to OFF. alter proc uspIdatos_ @iDProducto int output, @Descripcion nvarchar(50), @Precio money, @Stock int, @Notas text as Insert into Producto(IDProducto,Descripcion,Precio,Stock,Notas)values(@iDProducto,@Descripcion,@Precio,@Stock,@Notas) SET @iDProducto=@@IDENTITY

推荐答案

不,你不能。 但是...如果你将@iDProducto声明为INPUT值而不是OUTPUT,也许你可以......但是你无法返回它。 所以make你的想法:这是一个身份字段,SQL应该管理它,你应该返回它;或者它不是,它是从外部指定的,因此不需要返回它。 No, you can't. But...if you declared @iDProducto as an INPUT value rather than an OUTPUT, perhaps you could...but then you couldn't return it. So make your mind up: either this is an identity field, SQL should manage it, and you should return it; or it isn't, it is specified from outside, and so there is no need to return it.

您可以在插入命令之前使用此命令。 You can use this command before your insert command. SET IDENTITY_INSERT dbo.Producto ON;

alter proc uspIdatos_ @iDProducto int output, @Descripcion nvarchar(50), @Precio money, @Stock int, @Notas text as SET IDENTITY_INSERT Producto ON; Insert into Producto(IDProducto,Descripcion,Precio,Stock,Notas)values(@iDProducto,@Descripcion,@Precio,@Stock,@Notas) SET @iDProducto=@@IDENTITY SET IDENTITY_INSERT Producto OFF;

更多推荐

无法为标识列插入显式值

本文发布于:2023-11-16 01:32:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1599777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标识   显式值

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!