Tuesday 17 June 2014

Integrity Constraint violated while importing data for unique identifier column in SQL Server

Following is the error message which came up when we tried inserting data from excel sheet into a database table using the Import and Export Wizard -

There was an error with input column "<ColumnName>" (168) on input "Destination Input" (75). The column status returned was: "The value violated the integrity constraints for the column."

The column for which it was showing the error was defined as a unique identifier in the table. 

Such an error can come up when we try to insert string data 'varchar' for unique identifier fields (GUIDs). The simple trick is to enclose these GUIDs (format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) in braces {}.

Thus a GUID string such as {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} in the excel sheet data should get rid of this error !

2 comments: