Is their an int field in mysql where negative numbers are not allowed? or more specifically if a negative number is inserted into the field it will insert a zero. I ask this because we have a scoring system and we don’t allow people to have negative scores. So if their score does reach bellow zero, it will just insert a zero instead. I’m trying to do this without having to query the user’s score to check if it will fall bellow zero.
Share
In addition to the DDL change (INT UNSIGNED) that others have recommended, I’d also change your application logic. You say:
You don’t have to explicitly check in a separate query:
Now your application cannot UPDATE
scoreto fall below zero, nor will it generate errors or warnings depending on the SQL mode.