简体   繁体   English

mySQL 添加具有 NULL 值的列

[英]mySQL adding column with NULL values

I am using mySQL and am trying to get my head around the difference between NULL and empty.我正在使用 mySQL 并试图弄清楚 NULL 和空之间的区别。 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.然后列中的每个字段都会自动填充为 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:如果您不喜欢空值,您可以使用default ,但 Null 更具描述性:

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.通常,您应该使用 null,因为这意味着 -none 已为此列设置了值。

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.至于空间,我不知道 MySQL 正在处理空值,但我认为 NULL 占用的空间较少,因为 NULL 在大多数语言中通常是单例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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