插入身份列 [英] Insert into identity column

查看:74
本文介绍了插入身份列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有具有标识列的表.许多线程将从dotnet端运行,并将在此表中插入记录.

发生这种情况时,有时会出现错误:
无法将值NULL插入表"xyz"的表标识列"中;该列不允许为空."

Hi All,

I have table which has identity column. Many threads will be running from dotnet side and will be inserting records in this table.

When it is happening I am getting error some time:
"Cannot insert the value NULL into column ''identity column'', table ''xyz''; column does not allow nulls."

Thanks in advance.

推荐答案

无法将NULL值插入身份列",表"xyz"中;该列不允许空值."
您不清楚其中的哪一部分?

换句话说,这意味着什么:您已将一列定义为标识列.由于它是表中的标识列,因此它不能保存任何NULL值.您尝试在其中插入NULL,因此会出现错误.

现在,我认为您在这里必须缺少的是将"AutoIncrement"设置为true.只需执行此操作,然后如果在插入时忽略该列,则它将在每次插入时自动加1,并且错误应该消失了.

以防万一,请执行以下操作:编辑表格设计.选择该列,然后在其属性网格中找到身份"部分,可以在其中选择使其自动递增.
"Cannot insert the value NULL into column ''identity column'', table ''xyz''; column does not allow nulls."
Which part of it was not clear to you?

What it means in other words: You have defined a column as an identity column. Since it is an identity column in the table, it cannot hold any NULL value. You are trying to insert a NULL in that and thus you get an error.

Now, what I think you must be missing here is setting the ''AutoIncrement'' to true. Just do it and then if you ignore that column at the time of inserts, it would automatically increment by 1 on each insertion and error should be gone.

Just in case of how to do it: Edit the table design. Select the column and then in it''s property grid, you will find the Identity part where you will have an option to make it autoincrement.


通常不允许将值插入身份"列所以我想您已经使用SET IDENTITY_INSERT ON启用了此功能?
从多个线程将值插入到身份列应该被证明是困难的.如何防止线程在每次插入时分别对每次上的identity列使用相同的值,以及要在需要显式设置identity列的位置插入什么样的数据.

如果您向我们展示了执行这些插入操作的代码,那将是最好的.我们只需要相关的位,例如SQL语句以及您如何提供数据.

最好的问候,

-MRB
Inserting values into the identity column is usually disallowed so I presume you have used SET IDENTITY_INSERT ON to enable this?
Inserting values into an identity column from more than one thread should prove to be difficult. How are you keeping the threads from using the same value for the identity column on each every insert and what kind of data are you inserting where you need to explicitely set the identity column.

It would be best if you showed us the code that did these inserts. We only need the relevant bits like the SQL statement and how you''re supplying the data.

Best Regards,

-MRB


您不能这样做.

它不会工作.曾经.完全没有.不允许.

当您在列"identity"中使用时,您对数据库说:您要注意:我不在乎您在此字段中输入的数字,只需确保您从未重复即可."

如果您可以写该字段,则不要重复"位会直接显示在窗口之外.数据库(非常正确)抱怨,因为它与您已经给它的指令冲突.

想一想:您会被允许选择自己的门牌号码吗?不,因为每条街道上都有六间房屋,分别是数字"007"和二十个"42".
You can''t do it.

It won''t work. Ever. At all. It isn''t allowed.

When you make a column "identity" you are saying to the database: "You take care of this: I don''t care what numbers you give this field, just make sure that you never give a duplicate".

If you could write to the field, then the "don''t give a duplicate" bit goes right out the window. The database (very rightly) complains because it conflicts with the instructions you have already given it.

Think about it: Would you be allowed to pick your own house number? No, because every street would have six houses with the number "007" and twenty "42"s.


这篇关于插入身份列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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