mysql - 如果没有提供默认值,字段的默认值是多少?

标签 mysql phpmyadmin default-value

我希望这不是一个愚蠢的问题。您可以为所有变量或插入时的函数设置默认值。但是如果不需要插入该字段并且您不允许空值,那么您在 phpMyAdmin 中看到的“空白”值是什么?在查询中它是否作为空字符串等返回?

只是想弄清楚,我想查询所有记录,以便该记录中特定列的值不是“空”或空白或其他任何内容。

谢谢。

最佳答案

引用 manual ,

For data entry for a NOT NULL column that has no explicit DEFAULT clause, if an INSERT or REPLACE statement includes no value for the column, or an UPDATE statement sets the column to NULL, MySQL handles the column according to the SQL mode in effect at the time:

  • If strict SQL mode is not enabled, MySQL sets the column to the implicit default value for the column data type.
  • If strict mode is enabled, an error occurs for transactional tables and the statement is rolled back. For nontransactional tables, an
    error occurs, but if this happens for the second or subsequent row of a multiple-row statement, the preceding rows will have been inserted.

所以您现在的问题可能是,各种列数据类型的隐式默认值是什么?给你:

Implicit defaults are defined as follows:

  • For numeric types, the default is 0, with the exception that for integer or floating-point types declared with the AUTO_INCREMENT
    attribute, the default is the next value in the sequence.
  • For date and time types other than TIMESTAMP, the default is the appropriate “zero” value for the type. For the first TIMESTAMP column in a table, the default value is the current date and time. See Section 10.3, “Date and Time Types”.
  • For string types other than ENUM, the default value is the empty string. For ENUM, the default is the first enumeration value.

关于mysql - 如果没有提供默认值,字段的默认值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8558260/

相关文章:

php - mysql 将 varchar 转换为日期

php - 调用模型文件中非对象的成员函数 num_rows()

c++ - 在包装类中使用参数的默认值

PHP MYSQL 变量返回错误

mysql - phpMyAdmin,存储过程没有按预期工作

php - Docker:PhpMyAdmin的上传限制为2048KiB

php - 通过phpMyAdmin(Wordpress)上传.sql文件后定位或建立MySQL UN和PW

oracle - 可选的输出游标作为参数

Python:将函数参数的默认值传递给 *args 或 **kwargs

mysql - 有条款问题