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

HTML realizes real-time monitoring function of Hikvision camera

Recently the company has arranged to do some CCFA...

jQuery realizes the shuttle box function

This article example shares the specific code of ...

Summary of several APIs or tips in HTML5 that cannot be missed

In previous blog posts, I have been focusing on so...

Example code for implementing stacked carousel effect with HTML+CSS+JS

Effect: When the slideshow moves in one direction...

MySQL database deletes duplicate data and only retains one method instance

1. Problem introduction Assume a scenario where a...

JavaScript to achieve calendar effect

This article shares the specific code for JavaScr...

Basic statements of MySQL data definition language DDL

MySQL DDL statements What is DDL, DML. DDL is dat...

MySQL 5.6.33 installation and configuration tutorial under Linux

This tutorial shares the installation and configu...

A simple way to call desktop exe programs on a web page

This article mainly introduces how to call desktop...

MySQL 5.7 and above version download and installation graphic tutorial

1. Download 1. MySQL official website download ad...

MySQL database table and database partitioning strategy

First, let's talk about why we need to divide...

Summary of fragmented knowledge of Docker management

Table of contents 1. Overview 2. Application Exam...