[英]Update data from one table to another failing
I have two tables in two systems both have the same structure. 我在两个系统中有两个表具有相同的结构。 I want update the data in one table to other
我想将一个表中的数据更新为其他表
update Table1
set VIEW_CD = cmn.VIEW_CD,
VIEW_DETAIL = cmn.VIEW_DETAIL
FROM dbo.Table1 tbl
INNER JOIN dbo.Table2 cmn ON tbl.id = cmn.id
Both the columns in both the tables are null columns but I am ending up with the exception 两个表中的两列都是空列,但我最终会遇到异常
Cannot insert the value NULL into column column does not allow nulls.
无法将值NULL插入列列不允许空值。 INSERT fails.
INSERT失败。
I believe the problem is that you have NOT NULL
constraint on Table1
, you should drop it : 我相信问题是你在
Table1
上有NOT NULL
约束,你应该放弃它:
ALTER TABLE dbo.Table1 ALTER COLUMN VIEW_CD <columnType> NULL
Or this: 或这个:
ALTER TABLE dbo.Table1 ALTER VIEW_CD DROP NOT NULL
And then run the query once again. 然后再次运行查询。
Try this : 尝试这个 :
update Table1
set VIEW_CD = cmn.VIEW_CD,
VIEW_DETAIL = cmn.VIEW_DETAIL
FROM dbo.Table1 tbl
INNER JOIN dbo.Table2 cmn ON tbl.id = cmn.id
where VIEW_CD IS NOT NULL AND VIEW_DETAIL IS NOT NULL
The above will update Table1 with all the records from Table2 where the records doesn't contain any NULL values. 以上将使用Table2中的所有记录更新Table1,其中记录不包含任何NULL值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.