Summary of the characteristics of SQL mode in MySQL

Summary of the characteristics of SQL mode in MySQL

Preface

The SQL mode affects the SQL syntax that MySQL supports and the data validation checks that it performs.

The MySQL server can operate in different SQL modes, and can apply these modes differently for different clients, depending on the value of the sql_mode system variable. The DBA can set the global SQL mode to match site server operating requirements, and each application can set its session SQL mode to its own requirements.

The mode affects the SQL syntax that MySQL supports and the data validation checks it performs. This makes it easier to use MySQL in different environments and to use MySQL with other database servers.

Let’s take a look at the detailed introduction.

Setting the SQL Mode

To change the SQL mode at runtime, set the global or session sql_mode system variable using the SET statement.

SET GLOBAL sql_mode = 'modes';
SET SESSION sql_mode = 'modes';

Mode List

model Notes
ALLOW_INVALID_DATES Invalid dates generate an error
ERROR_FOR_DIVISION_BY_ZERO Division by 0 error
NO_BACKSLASH_ESCAPES The backslash character (\) is prohibited as an escape character in string literals. When this mode is enabled, backslash acts like any other normal character.
NO_UNSIGNED_SUBTRACTION Subtraction between integer values ​​(one of which is of type UNSIGNED ) produces an unsigned result by default. If the result is otherwise negative, an error occurs
NO_ZERO_IN_DATE '0000-00-00' is allowed and inserts produce a warning
ONLY_FULL_GROUP_BY The specified field in select must appear in groupby, otherwise an error will occur
STRICT_TRANS_TABLES Enable strict SQL mode for transactional storage engines, and, where possible, for nontransactional storage engines.
STRICT_ALL_TABLES Enable strict SQL mode for all storage engines. Invalid data values ​​are rejected.

For more details, please refer to https://dev.mysql.com/doc/ref...

Strict SQL Mode

The MySQL server can operate in different SQL modes, and can apply these modes differently for different clients, depending on the value of the sql_mode system variable. In strict SQL mode, the server upgrades certain warnings to errors.

Strict SQL mode applies to the following statements

  • ALTER TABLE
  • CREATE TABLE
  • CREATE TABLE ... SELECT
  • DELETE
  • INSERT
  • LOAD DATA
  • LOAD XML
  • SELECT SLEEP()
  • UPDATE

Within a stored procedure, if the procedure was defined while strict mode was in effect, single statements of the listed types are executed in strict SQL mode.

Strict SQL mode applies to the following errors, which represent a class of errors where an input value is invalid or missing. A value is invalid if it has the wrong data type for the column or might be out of range. If a new row to be inserted does not contain a value for a column that has no explicit DEFAULT clause in its definition that is NOT NULL , then the value is missing.

  • ER_BAD_NULL_ERROR
  • ER_CUT_VALUE_GROUP_CONCAT
  • ER_DATA_TOO_LONG
  • ER_DATETIME_FUNCTION_OVERFLOW
  • ER_DIVISION_BY_ZERO
  • ER_INVALID_ARGUMENT_FOR_LOGARITHM
  • ER_NO_DEFAULT_FOR_FIELD
  • ER_NO_DEFAULT_FOR_VIEW_FIELD
  • ER_TOO_LONG_KEY
  • ER_TRUNCATED_WRONG_VALUE
  • ER_TRUNCATED_WRONG_VALUE_FOR_FIELD
  • ER_WARN_DATA_OUT_OF_RANGE
  • ER_WARN_NULL_TO_NOTNULL
  • ER_WARN_TOO_FEW_RECORDS
  • ER_WRONG_ARGUMENTS
  • ER_WRONG_VALUE_FOR_TYPE
  • WARN_DATA_TRUNCATED

Acknowledgements

Thank you for reading this. I hope this article can help you. Thank you.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • How to enable strict mode in mysql
  • Learn SQL statements (powerful group by and select from modes)
  • Commonplace talk about the usage of MYSQL pattern matching REGEXP and like
  • Mysql SQL Server Mode Introduction
  • PHP mysql class based on singleton mode
  • NoSQL Anti-Patterns - Document Databases
  • Detailed analysis of binlog_format mode and configuration in MySQL
  • How to deal with Warning when MySQL enables skip-name-resolve mode

<<:  How to effectively compress images using JS

>>:  Implementation of Docker to build Zookeeper&Kafka cluster

Recommend

JavaScript implements the nine-grid mobile puzzle game

This article shares the specific code for JavaScr...

How to delete folders, files, and decompress commands on Linux servers

1. Delete folders Example: rm -rf /usr/java The /...

How to use environment variables in nginx configuration file

Preface Nginx is an HTTP server designed for perf...

Deployment and Chinese translation of the docker visualization tool Portainer

#docker search #docker pull portainer 1. Download...

Detailed explanation of where Docker saves log files

Table of contents Where are the logs stored? View...

Organize the common knowledge points of CocosCreator

Table of contents 1. Scene loading 2. Find Node 1...

centos7.2 offline installation mysql5.7.18.tar.gz

Because of network isolation, MySQL cannot be ins...

Detailed Analysis of Explain Execution Plan in MySQL

Preface How to write efficient SQL statements is ...

Common methods and problems of Docker cleaning

If you use docker for large-scale development but...

Three common ways to embed CSS in HTML documents

The following three methods are commonly used to d...

MariaDB under Linux starts with the root user (recommended)

Recently, due to the need to test security produc...

MySQL full-text search usage examples

Table of contents 1. Environmental Preparation 2....

Linux Jenkins configuration salve node implementation process diagram

Preface: Jenkins' Master-Slave distributed ar...

Explanation of the steps for Tomcat to support https access

How to make tomcat support https access step: (1)...