标识列的显式值

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

大家好, 能否请您点击下面的错误? 只有在使用列列表并且IDENTITY_INSERT为ON时才能指定表''tblreg''中标识列的显式值。 感谢您的帮助。

解决方案

如果您将列声明为 Identity = true ,然后SQL将处理值并将按顺序分配它们,以便您不能重复。如果您在任何时候尝试通过INSERT或UPDATE操作设置该字段的值,SQL将抛出该异常。 最常见的错误是尝试和执行匿名INSERT操作:

INSERT INTO MyTable VALUES( 1 , 2 , 3 )

表中的第一列是ID列,声明为identity。 SQL尝试以数字列顺序分配此类插入,因此尝试将第一个值写入Identity字段。使用时始终列出列,并且您不会遇到问题:

INSERT INTO MyTable(ProdCount,ItemNo,Bananas) VALUES ( 1 , 2 , 3 )

它表示你试图在一个声明为 Identity colunm的colunm中插入一个值。 看看下面的链接以了解身份。 en.wikipedia/ wiki / Identity_column http:/ /www.sqlteam/article/understanding-identity-columns 解决方案: - 要么不指定值您声明为Identity的colunm的Insert语句colunm。或者,如果您想继续使用显式值,请查看以下链接以解决您的问题。 blog.sqlauthority/2007/03/28/sql-server-fix-error-8101-an-explicit-value-for-the-identity-column-in -table-可以仅待指定-时-A-柱一览被使用的和 - IDENTITY_INSERT-是开/

Hi Everyone, Can you please with the error below? An explicit value for the identity column in table ''tblreg'' can only be specified when a column list is used and IDENTITY_INSERT is ON. Thanks for your help.

解决方案

If you declare a column as Identity = true, then SQL will handle the values and will assign them sequentially so that you cannot get repeats. If you try at any time to set the value of that field via an INSERT or UPDATE operation, SQL will throw that exception. The most common mistake is to try and do an "anonymous" INSERT operation:

INSERT INTO MyTable VALUES (1, 2, 3)

Where the first column in the table is the ID column, declared as identity. SQL tries to assign such inserts in numerical column order, and so tries to write the first value into the Identity field. USe names columns at all times and you won''t get the problem:

INSERT INTO MyTable (ProdCount, ItemNo, Bananas) VALUES (1, 2, 3)

Its indicating you are trying to insert a value in a colunm which is declared as an Identity colunm. Have a look at below link to understand Identity. en.wikipedia/wiki/Identity_column www.sqlteam/article/understanding-identity-columns Solution :- Either do not specify value in your Insert statement for the colunm which is declared as an Identity colunm. Or incase if you want to continue with explicit value then have a look at below link to resolve your issue. blog.sqlauthority/2007/03/28/sql-server-fix-error-8101-an-explicit-value-for-the-identity-column-in-table-can-only-be-specified-when-a-column-list-is-used-and-identity_insert-is-on/

更多推荐

标识列的显式值

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

发布评论

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

>www.elefans.com

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