无法在表中插入新列 [英] Can not insert a new column in a table

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

问题描述

嗨朋友们:



我有一个产品我要在其中创建新列Modified_By的表格和Modified_Date_Time。此列不允许空值。



但是,由于数据库已经有数据,为了创建此列,我必须定义为允许空值。然后,我运行一个更新新列的过程。最后一步是取消选中允许空值。属性,但是当我试图保存表格更改时,我收到以下错误:



''Product_Details''表 - 无法修改表格。

无法将值NULL插入列''Modified_Date_Time'',表''Vendor Products.dbo.Tmp_Product_Details'';列不允许空值。 INSERT失败。声明已经终止。



所有行都使用Modified_By中的正确值成功更新。和Modified_Date_Time;专栏,所以我不知道为什么我会收到这个错误...无论如何,它似乎是一个新的临时。表是由SQL Server 2008创建的,因为我没有任何名称为Tmp_Orders的表格



任何帮助都表示赞赏。谢谢:)

Hi Friends:

I have a "Product" table in which I want to create a new columns "Modified_By" and "Modified_Date_Time". This columns does not allow nulls.

However, as the database already has data, in order to create this column I had to defined as "allowing nulls". Then, I run a process which updated the new column. The last step was to uncheck the "Allow nulls" property, but when I tried to save the table changes, I got the following error:

''Product_Details'' table - Unable to modify table.
Cannot insert the value NULL into column ''Modified_Date_Time'', table ''Vendor Products.dbo.Tmp_Product_Details''; column does not allow nulls. INSERT fails. The statement has been terminated.

All the rows were succesfully updated with the correct value in the "Modified_By" and "Modified_Date_Time" column, so I don''t know why I get this error...Anyway, it seems like a new "temporary" table was created by SQL Server 2008, because I don''t have any table with the name "Tmp_Orders"

Any help is appreciated..Thanks :)

推荐答案

尝试在关闭接受空值时为列设置默认值。这应该允许你改变它。
Try setting a default value for the column when you turn off accepting nulls. That should allow you to change it.


当我过去必须这样做时,我已经完成了多步骤。主要是因为验证过程的每个步骤都很容易,而且很容易做到。 (KISS原则)



1)创建新列将最初允许为NULL。

2)更新数据以使这些数据具有有效值列。

3)改变表格使列成为非空。
When I''ve had to do this in the past, I''ve done it in a multi-step process. Mostly because it''s just easy to validate each step of the process and it''s easy to do. (KISS principle)

1) Create your new columns will NULL allowed initially.
2) Update your data to have valid values in these columns.
3) Alter the tables to make the columns NOT NULL.


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

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