How to add a positive integer constraint to a integer column in MySQL?

后端 未结 5 949
情深已故
情深已故 2021-01-17 12:01

How can we add a constraint which enforces a column to have only positive values.

Tried the following mysql statement but it doesn\'t work

create tab         


        
5条回答
  •  时光取名叫无心
    2021-01-17 12:09

    just use unsigned to allow only positive values.

    CREATE TABLE hello 
    (
        world int unsigned
    );
    
    • SQLFiddle demo

    uncomment the line and you will see the error saying: Data truncation: Out of range value for column 'world' at row 1:

提交回复
热议问题