I solved it i just change my condition from QUANTITY >= 0
TO QUANTITY>0 OR QUANTITY=0
and it starts working fine now. :)
Sql Check constraint?
-
13-06-2023 - |
Question
I am working on C# app using SQL Server as database here is a very simple problem which I could not find out till now. I created a check constraint on my QUANTITY
column like this:
QUANTITY >= 0
The quantity is updating from C# and I don't want the quantity to become less than zero but when my quantity is 2 and I subtract 2 so it should allow zero as a quantity but not less than 0 but it throws following exception :
The UPDATE statement conflicted with the CHECK constraint \"CK_ITEM_DETAILS_QUANTITY\". The conflict occurred in database \"MyDatabase\", table \"dbo.ITEM_DETAILS\", column 'QUANTITY'.\r\n The statement has been terminated.
Any idea what I'm doing wrong?
Solution 2
OTHER TIPS
Without code it is not possible to say what exactly went wrong, but one thing is for sure: You are trying to write a value where the condition QUANTITY >= 0
does not hold. You seem to mistakenly assume that you aren't, but the message is unambiguous and there are no known bugs in that area. Maybe a floating point rounding issue?