Detailed explanation of the difference and usage of quotes and backticks in MySQL

Detailed explanation of the difference and usage of quotes and backticks in MySQL

Preface

So I wrote this blog. This blog also recommends some knowledge from articles by big guys. If there is any infringement, please contact me! If someone is lucky enough to see this blog, I hope it can be helpful to you. If there are any mistakes, you can point them out directly! !

1. Single quotes:

Let's first introduce single quotes. The word '男' in the picture below is the English single quote.

Why use single quotes? In SQL, some varchar (string, and other string types) need to use single quotes instead of using them directly.

Generally, in the database, numeric types do not need to be enclosed in single quotes. Let's look at the example below:

The above mentioned that in general, quotation marks are not needed. However, if in different visual database tools, some of them can be queried with quotation marks and no errors will be reported. However, we still need to write them with correct SQL statements to avoid bugs in the future.

2. Backticks:

It is a symbol introduced to distinguish MYSQL reserved words from ordinary characters.

We can see the example below:

This is a normal query. What if we put quotation marks around gender? What will happen in this case?

This is incorrect in SQL syntax, but some database visualization tools do not report an error, but we cannot query any values. Let’s add it and see what happens if we add backquotes.

This will result in the same situation as the first one. This is used to distinguish the difference between the two. Otherwise, the database tool will think they are all strings and the search will not be successful! !

Note the following: MySQL reserved words must be distinguished by backticks! ! !

The so-called reserved words are SQL instructions for databases such as select database insert. When we have to use them as table names and field names, we must add backticks to prevent the compiler from considering this part as a reserved word and generating an error.

You may also be interested in:
  • Problems with using multiple single quotes and triple quotes in MySQL concat
  • How to insert a value containing single quotes or backslashes in MySQL statements
  • A detailed analysis of the murder caused by a misplaced double quote in MySQL
  • About Mysql query with single quotes and inserting strings with single quotes
  • Analysis of MYSQL performance issues caused by a single quote

<<:  Uniapp implements DingTalk scan code login sample code

>>:  CSS achieves highly adaptive full screen

Recommend

How to change the Ali source in Ubuntu 20.04

Note that this article does not simply teach you ...

How to solve the problem of ERROR 2003 (HY000) when starting mysql

1. Problem Description When starting MYSQL, a pro...

Detailed implementation plan of Vue front-end exporting Excel files

Table of contents 1. Technology Selection 2. Tech...

The complete code of the uniapp packaged applet radar chart component

Effect picture: The implementation code is as fol...

The most complete package.json analysis

Table of contents 1. Overview 2. Name field 3. Ve...

Specific implementation methods of MySQL table sharding and partitioning

Vertical table Vertical table splitting means spl...

Vue sample code for online preview of office files

I'm working on electronic archives recently, ...

HTML form application includes the use of check boxes and radio buttons

Including the use of check boxes and radio buttons...

MySQL 8.0.18 adds users to the database and grants permissions

1. It is preferred to use the root user to log in...

Detailed steps to install mysql5.7.18 on Mac

1. Tools We need two tools now: MySQL server (mys...

CSS box hide/show and then the top layer implementation code

.imgbox{ width: 1200px; height: 612px; margin-rig...

CSS and HTML and front-end technology layer diagram

The relationship between Javascript and DOM is ve...

Nginx dynamic and static separation implementation case code analysis

Separation of static and dynamic Dynamic requests...

MySql import CSV file or tab-delimited file

Sometimes we need to import some data from anothe...