如果未提供默认值,则该字段的默认值是多少? [英] What is the default value for a field if no default value is provided?

查看:84
本文介绍了如果未提供默认值,则该字段的默认值是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I hope this isn't a dumb question. You can set a default value for all variables or a function for when it is inserted. but if the field is not required to insert and you don't allow null values, what is the "blank" value that you see in phpMyAdmin? in a query is it returned as empty string, etc?

我只是想弄清楚,我想查询所有记录,以使该记录中特定列的值不是空"或空白或任何其他值.

just trying to figure it out, I want to query for all records such that the value for a specific column in that record is not "empty" or blank or whatever.

谢谢.

推荐答案

引用

用于没有显式默认值的NOT NULL列的数据输入 子句,如果INSERT或REPLACE语句不包含 列,或UPDATE语句将列设置为NULL,MySQL处理 该列根据当时有效的SQL模式:

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:

  • 如果未启用严格的SQL模式,则MySQL会将列设置为列数据类型的隐式默认值.
  • 如果启用严格模式,则事务表将发生错误,并且该语句将回滚.对于非事务处理表,
    发生错误,但是如果在第二行或后续行中发生这种情况 多行语句,将插入前面的行.
  • 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.

因此,您现在的问题可能是,各种列数据类型的隐式默认值是什么?在这里,您去了:

So your question now may be, what are the implicit default values for the various column data types? Here you go:

隐式默认值定义如下:

Implicit defaults are defined as follows:

  • 对于数字类型,默认值为0,但对于用AUTO_INCREMENT声明的整数或浮点类型,则为默认值
    属性,默认值为序列中的下一个值.
  • 对于除TIMESTAMP以外的日期和时间类型,默认值为该类型的适当零"值.对于第一个TIMESTAMP列 在表中,默认值为当前日期和时间.请参见第10.3节日期和时间类型".
  • 对于ENUM以外的其他字符串类型,默认值为空字符串.对于ENUM,默认值为第一个枚举值.
  • 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.

这篇关于如果未提供默认值,则该字段的默认值是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆