search

Home  >  Q&A  >  body text

MySQL 字段默认值 一般设null 还是空字符串?

MySQL 字段默认值 一般设null 还是空字符串?设nul 和空字符串的区别是什么,各有什么优缺点。

高洛峰高洛峰2785 days ago968

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 14:41:43

    Empty strings are OK, try not to use null. This is a keyword, which will be a pitfall in your future index optimization

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 14:41:43

    Not sure, but it seems like an empty string is stored. You can have a piece of data with a null value, and then check the type of the null field value. If it is string, it is an empty string, if not, it is null.
    To put it simply,
    var testString = ""; //This declares a testString string, equal to "", which is already stored in memory.
    var testString = null; //This declares a testString variable, which is just a variable and does not actually allocate memory space.
    If you don’t understand, just think about it this way. If you use a writing word to represent this process, "" means a blank piece of paper with no writing on it. And null means you don't even have a blank piece of paper.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 14:41:43

    not null default ""

    reply
    0
  • Cancelreply