Problem Description:
When execution inserts a query result into a table that already exists, the error is as follows:
Cannot insert value NULL into column ' column name ', table ' table name to insert '; column does not allow null values. INSERT failed.
The following statements are executed:
INSERT into Bitcoin.dbo.CoinbaseTransaction (transactionhash)
SELECT dbo. Bitcointransaction.transactionhash from
[bitcoin].[ DBO]. Bitcointransaction
INNER JOIN [coinbasetransaction] on [bitcoin].[ DBO]. [Coinbasetransaction]. [Bitcointransactionid]=[bitcoin]. [dbo]. Bitcointransaction. [Bitcointransactionid]
Analysis:
The table I was inserting was missing a (key) primary key, so a field was selected as the primary key in the table to be inserted.
However, the same error is still displayed when you select a column as the primary key.
And then search the Internet:
The primary key of the general EF is automatically generated by the system. You may have ignored your explicit assignment.
In fact, the general formula is the primary key from the growth, and then the EF save will automatically give the UID back to the latest values in the database.
It is troublesome for you to maintain a primary key manually. Do not recommend to do
ALTER TABLE [Bitcoin]. [dbo]. [Coinbasetransaction] Add Coinbaseid bigint
INSERT into Bitcoin.dbo.CoinbaseTransaction (Transactionhash)
SELECT dbo. Bitcointransaction.transactionhash from
[bitcoin].[ DBO]. Bitcointransaction
INNER JOIN [coinbasetransaction] on [bitcoin].[ DBO]. [Coinbasetransaction]. [Bitcointransactionid]=[bitcoin]. [dbo]. Bitcointransaction. [Bitcointransactionid]
Message 512, Level 16, State 1, line 2nd
The subquery returns more than one value. This is not allowed when the subquery follows =,!=, <, <=, >, >=, or the subquery is used as an expression.
Check the two subquery select [1YUE] from View_1, and select [Lgmc]from view_1 is not a lot of records in the result set. if any, use the = number is not appropriate. You should consider using the IN keyword or the table's own connection and other methods.