Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update data from one table to another failing

Tags:

sql

sql-server

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. INSERT fails.

like image 588
user3595236 Avatar asked Jan 20 '26 21:01

user3595236


1 Answers

I believe the problem is that you have NOT NULL constraint on Table1 , you should drop it :

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.

like image 177
sagi Avatar answered Jan 23 '26 11:01

sagi