SQL Server 2008 R2. I’m getting an exception due to a violated table constraint (this is in the [ecs_subpopulaterm_Public_09_2013] table): INSERT statement conflicted with the CHECK constraint "CK_ecs_subpo_M1_RE_26A5A30" The constraint is on valid values: [M1_RES_PHN_CD]='G' OR [M1_RES_PHN_CD]='B' OR [M1_RES_PHN_CD]='*' Yet the data set being imported has values outside of the constraint. SELECT M1_RES_PHN_CD FROM [ecs_subpopulaterm_Public_09_2013] GROUP BY M1_RES_PHN_CD M1_RES_PHN_CD G B * M1_RES_PHN_CD is defined as varchar(10) and allows NULLS in the table. I queried the table for WHERE M1_RES_PHN_CD IS NULL and it returned no rows. Do you have any thoughts as to why the CHECK constraint returned an error, but appears to have allowed blanks (spaces) to be inserted (first line under column heading M1_RES_PHN_CD in result set)?
Your question is twofold if I understand it: - Why did the CHECK constraint cause an error with an insert? - How can there be rows in the table not fullfilling the CHECK constraint condition? First question: The only reason I can think of is that you are trying to import data which does not fullfill the CHECK condition of the constraint. You need to find out which row from the source data causes the check condition to not be fullfilled. Second question: If you already have data in your table, and add a CHECK constraint, using WITH NOCHECK, you can have whatever data you want in the table, the constraint will only validate new or updated rows.