Thursday, March 8, 2012

Check Constraint

In our database we have an indexed field that is using unique values, so in the index we turned on the unique property. Now with some changes we made in the application this value can be Null (could not be Null in the past). When we have more as 1 value having value Null we get an exception of unique key violation.

Therefor we want to make an check constraint the checks if the value allready exists when the value is not Null.

Is this possible and how can it be done?

You're going to need to use a trigger to check the values in the way you described.|||Hi,

I'm getting the same error.
When I try to add a new user I receive this errror:

ystem.Data.ConstraintException: Column 'User ID' is constrained to be unique. Value '{37525b24-d982-470d-9d1c-e3b3c7536958}' is already present.
at System.Data.UniqueConstraint.CheckConstraint(DataRow row, DataRowAction action)
at System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent)

Unfortunately I have only one entry on my db with this User ID value. Moreover I have try to delete all my users with BU.
Can anybody help me?

Thanks a lot,

F.T

No comments:

Post a Comment