The value violated the integrity constraints for the column

前端 未结 8 1382
情深已故
情深已故 2020-12-03 06:49

I am trying to import the data from Excel file into SQL Server database. I am unable to do so because I am getting following errors in the log file. Please help. The log err

相关标签:
8条回答
  • 2020-12-03 06:57

    I've found that this can happen due to a number of various reasons.

    In my case when I scroll to the end of the SQL import "Report", under the "Post-execute (Success)" heading it will tell me how many rows were copied and it's usually the next row in sheet which has the issue. Also you can tell which column by the import messages (in your case it was "Copy of F2") so you can generally find out which was the offending cell in Excel.

    I've seen this happen for very silly reasons such as the date format in Excel being different than previous rows. For example cell A2 being "05/02/2017" while A3 being "5/2/2017" or even "05-02-2017". It seems the import wants things to be perfectly consistent.

    It even happens if the Excel formats are different so if B2 is "512" but an Excel "Number" format and B3 is "512" but an Excel "Text" format then the Cell will cause an error.

    I've also had situations where I literally had to delete all the "empty" rows below my data rows in the Excel sheet. Sometimes they appear empty but Excel considers them having "blank" data or something like that so the import tries to import them as well. This usually happens if you've had previous data in your Excel sheet which you've cleared but haven't properly deleted the rows.

    And then there's the obvious reasons of trying to import text value into an integer column or insert a NULL into a NOT NULL column as mentioned by the others.

    0 讨论(0)
  • 2020-12-03 07:07

    It usually happens when Allow Nulls option is unchecked.

    Solution:

    1. Look at the name of the column for this error/warning.
    2. Go to SSMS and find the table
    3. Allow Null for that Column
    4. Save the table
    5. Rerun the SSIS

    Try these steps. It worked for me.

    See this link

    0 讨论(0)
  • 2020-12-03 07:10

    Delete empty rows from Excel after your last row of data!

    Some times empty rows in Excel are still considered as data, therefore trying to import them in a table with one or more non nullable columns violates the constrains of the column.

    Solution: select all of the empty rows on your sheet, even those after your last row of data, and click delete rows.

    Obviously, if some of your data really does vioalte any of your table's constraints, then just fix your data to match the rules of your database..

    0 讨论(0)
  • 2020-12-03 07:10

    As a slight alternative to @FazianMubasher's answer, instead of allowing NULL for the specified column (which may for many reasons not be possible), you could also add a Conditional Split Task to branch NULL values to an error file, or just to ignore them:

    enter image description here

    enter image description here

    0 讨论(0)
  • 2020-12-03 07:10

    the point can be if you are not using valid login for linked server. Problem is on destination server side.

    There are few steps to try:

    1. Align db user and login on destination server: alter user [DBUSER_of_linkedserverlogin] with login = [linkedserverlogin]

    2. recreate login on destination server used by linked server.

    3. Backup table and recreate it.

    2nd resolved my issue with "The value violated the integrity constraints for the column.".

    0 讨论(0)
  • 2020-12-03 07:12

    Teradata table or view stores NULL as "?" and SQL considers it as a character or string. This is the main reason for the error "The value violated the integrity constraints for the column." when data is ported from Teradata source to SQL destination. Solution 1: Allow the destination table to hold NULL Solution 2: Convert the '?' character to be stored as some value in the destination table.

    0 讨论(0)
提交回复
热议问题