Limit INT data types (only positive)

0

Good afternoon.

I was searching the internet and found nothing.

What I want to do is to limit all the INT fields to accept only the positives. Is there any SQL function to do this?

You could put an IF that validates that, but I do not want it to be the solution.

Greetings

    
asked by Nahuel Picca 05.02.2018 в 18:56
source

2 answers

1

Well, for this situation you just have to add a constraint to your table, to always validate that they are positive. This would be more or less the constraint:

ALTER TABLE TuTabla ADD CONSTRAINT CK_Columna_Positivos CHECK (Columna > 0)
    
answered by 06.02.2018 / 13:56
source
0

In my case valid at the application level and that's where I validate that the data entered is positive, I do it with the jquery validate plugin. To others it is of great help to validate any field and its type of data.

That's the way I do it does not mean it's the best way, but it works for me and you can also set the message you want to show.

    
answered by 05.02.2018 в 19:50