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

MySQL query example explanation through instantiated object parameters

This article will introduce how to query data in ...

Web Design Experience: Efficiently Writing Web Code

Originally, this seventh chapter should be a deep ...

Comparative Analysis of UI Applications of Image Social Networking Sites (Figure)

In our life, work and study, social networks have ...

mysql three tables connected to create a view

Three tables are connected. Field a of table A co...

HTML Basics: The basic structure of HTML

The basic structure of HTML hypertext documents is...

Detailed explanation of MySQL Workbench usage tutorial

Table of contents (I) Using Workbench to operate ...

The forgotten button tag

Note: This article has been translated by someone ...

MySQL 20 high-performance architecture design principles (worth collecting)

Open Source Database Architecture Design Principl...

Example of downloading files with vue+django

Table of contents 1. Overview 2. Django Project 3...