Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql integer default value 0

Tags:

sql

integer

mysql

I have 4 integer columns in my table. They are not required to be filled. So some of them may be filled, some not. When they are not filled, mysql add 0 to that column. I tried to change column default value to NULL and it told Invalid default value. Is there any way to get empty row without having there the zero?

like image 737
user3026704 Avatar asked Nov 24 '13 08:11

user3026704


1 Answers

"Is there any way to get empty row without having there the zero?"

To have NULL in the column by default use the following syntax in create table:

`column` int(10) unsigned DEFAULT NULL,

To alter the existing column:

ALTER TABLE table_name CHANGE COLUMN `column_name` `column_name` int(10) unsigned DEFAULT NULL;
like image 124
user4035 Avatar answered Sep 20 '22 16:09

user4035