MySQL study notes property SQL_MODE

In a recent study "MySQL Technology Insider: SQL Programming" and took notes, notes of this blog is a type of blog, share it, to facilitate their review later, it can also help others

SQL_MODE: MySQL is a unique property, very versatile and can be achieved by setting the property to support certain functions

 # 全局的SQL_MODE 
 SELECT @@global.sql_mode;
 # 当前会话的SQL_MODE
 SELECT @@session.sql_mode; 

SQL_Mode default value is empty, it can be provided for SQL_mode mysql configuration file (the my.ini or the my.cnf), or disposed directly on the command

Strict mode: refers to the sql_mode STRICT_TRANS_TABLES or the STRICT_ALL_TABLES, strict mode is not allowed to set the illegal operation, such as the field of non-null value is written to Null's requirements, or the writing is not valid date data, such as' 2019 -09-40 '

SET GLOBAL sql_mode ='STRICT_TRANS_TABLES';
SET GLOBAL sql_mode ='STRICT_ALL_TABLES';

Data original data exist, do not directly set, with concat connected:

set @@session.sql_mode=concat(@@sql_mode,',IGNORE_SPACE');
  • STRICT_TRANS_TABLES: Enable strict mode, only affects the transaction table does not affect the non-transactional table, if a value can not be written to the transaction table (eg storage engine is InnoDB), it interrupts the current operation does not affect non-transactional tables (such as storage engine is MYISAM)
  • STRICT_ALL_TABLES: When enabled STRICT_ALL_TABLES, strict mode is enabled on the table for all engines
  • ANSI_QUOTES: ANSI_QUOTES then enabled, can not be used to refer to a string double quotation marks, because the open this mode, double quotes is interpreted as an identifier
  • ALLOW_INVALID_DATES: When this mode is enabled, will not be fully open for inspection dates, for example, only check whether the month from 1 to 12, date is 1 to 31, this test for date, datetime types is possible, but for the timestamp is no effect
  • ERROR_FOR_DIVISION_BY_ZERO: the insert or update process, if the data is divided by 0 (or the MOD (
    X, 0)) produces an error, if not open change mode, the data is divided by 0, NULL value is returned the MySQL
  • HIGH_NOT_PRECEDENCE NOT: open the old version of the expression priorities, such as Not a between b and c is interpreted as not (a between b and c), but in some older versions of MySQL is interpreted as (not a) between b and c if you want to use this older version will open HIGH_NOT_PRECEDENCE NOT
  • IGNORE_SPACE: Ignore the space between the function name and parentheses, this property is not turned on by default, it is generally not recommended to open, such as certain special circumstances can open, such as select count from t (1); there will be a space between the count error, will not open after the error, but generally is not directly in the function spaces and brackets, unless there is a table or column names also named count, this situation would spaces, table name, this is not a table count name, but the name of the function
  • GRANT prohibit users create a blank password: NO_AUTO_CREATE_USER
  • NO_AUTO_VALUE_ON_ZERO: This property is set to automatically increase the column does not permit write-zero value, also written zero or null, not write 0, if 0 is written, the data sheet had no data, will write an order analogy
  • NO_BACKSLASH_ESCAPES: backslash "" as ordinary characters rather than escapes
  • NO_DIR_IN_CREATE: ignore all INDEX DIRECTORY and DATE DIRECTORY options when creating a table
  • NO_ENGINE_SUBTRACTION: used storage engine is disabled or not compiled, you use the default storage engine, and an exception is thrown,
  • NO_UNSIGNED_SUBTRACTION: Enabling this property, two unsigned subtraction type signed return type
  • NO_ZERO_DATE: 0 format does not allow writes to date, such as "0000-00-00 00:00:00", after enabling this property, this type of data will be written Throws
  • In the case of strict mode, the date and month of zero is not allowed: NO_ZERO_IN_DATE
  • ONLY_FULL_GROUP_BY: If you select the error will occur is not listed in the group by
  • PAD_CHAR_TO_FULL_LENGTH: For char type field, query time not to intercept empty data, the so-called empty data is automatically populated data of 0x20
CREATE TABLE t (a CHAR(10));
INSERT INTO t SELECT 'a';

Here Insert Picture Description
By default query is that, if you set PAD_CHAR_TO_FULL_LENGTH, check out are:
Here Insert Picture Description

  • REAL_AS_FLOAT: The REAL as a synonym for FLOAT instead of a synonym for double
  • PIPES_AS_CONCAT: the "||" string concatenation operator regarded as, or instead of operators, and that it is the same oracle

Here are a combination of several options:

  • ANSI: equivalent to RELA_AS_FLOAT, and combinations PIPES_AS_CONCAT ANSI_QUOTES, IGNORE_SPACE of
  • ORACLE: equivalent to the combination PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, NO_FIELD_OPTIONS and the NO_AUTO_CREATE_USER
  • TRADITIONAL:等同于STRICT_TRANS_TABLES、STRICT_ALL_TABLES、NO_ZERO_IN_DATE、NO_ZERO_DATE、ERROR_FOR_DIVISION_BY_ZERO、NO_AUTO_CREATE_USER、NO_ENGINE_SUBSTITUTION的组合
  • MSSQL: equivalent to the combination PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS and the NO_FIELD_OPTIONS
  • DB2: equivalent to the combination PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS and the NO_FIELD_OPTIONS
  • MYSQL323: equivalent to the combination of NO_FIELD_OPTIONS and HIGH_NOT_PRECEDENCE
  • MYSQL40: equivalent to the combination of NO_FIELD_OPTIONS and HIGH_NOT_PRECEDENCE
  • MAXDB: equivalent to the combination PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS, NO_TABLE_OPTIONS, NO_FIELD_OPTIONS and the NO_AUTO_CREATE_USER

Guess you like

Origin www.cnblogs.com/mzq123/p/11668604.html