Wednesday, September 18, 2013

TSQL Errors

Error 1: Cannot define PRIMARY KEY constraint on nullable column in table 

Cause: set ansi null default on, when you create a new col

Solution: explicitly state not null 


Error 2: The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object 

Cause: Duplicate value for the desired columns

Solution: Run the following query to check the dup key, assuming unique index is on col1

select Col1 , count(*)
from Customers 
group by col1
having count(*) > 1

No comments:

Post a Comment