简体   繁体   中英

mySQL adding column with NULL values

I am using mySQL and am trying to get my head around the difference between NULL and empty. If I add a column to my table using...

alter table data add result VARCHAR(4);

Then every field in the column is automatically populated with NULL.

Does this take up any more space than an empty field? How could I add that column with blank values instead?

You can use default , if you don;t like nulls, but Null is more descriptive:

alter table data add result VARCHAR(4) DEFAULT ''

Generally you should be using null, as it means -none has set a value to this column.

As for the space I am not aware is MySQL is treating empty values, but I assume that NULL takes less space, because NULL is generally a singleton in most languages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM