Would it be possible to create a database-level restriction to prevent creating a row that has a column x INT with a value that already exists and is above 0?
Is there a way to use CONSTRAINT for this purpose?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A possible solution is to do the following:
Now, the column
myfieldmight be NULL. So when we do the following, there will be a total of 0 errors.Each and every row has a unique value in the column
myfield, but there is still the possibility to create rows where the value in this particular column isNULLwhich is almost exactly what I wanted. I wanted all values above 0 unique, this is all aboveNULL. The beauty of this solution is that it feels more ‘professional’, no unnecessary logic.