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

后端 未结 5 913
情深已故
情深已故 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:14

    The way to fix this is to explicitly tell MySQL Server to create an Unsigned integer.

    CREATE TABLE tbl_example ( 
    example_id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
    example_num INT UNSIGNED NOT NULL, 
    example_text TEXT 
    PRIMARY KEY (`example_id`) 
    ); 
    

提交回复
热议问题