Cannot insert value null into column ', table '; column does not allow null values. INSERT failed.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.