欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

MySQL中单引号和反引号的区别是什么?

程序员文章站 2022-03-19 08:54:03
...
之前在MySQL建表和查询的时候都用的单引号,后来发现有问题,同学提醒要用反引号,最近发现反引号也会出问题:
1.
2.


在网上看到有说,反引号是为了区分MySQL的保留字和普通字符,这样的话第2个可以解释,但是第1个是为什么呢。
其实单引号和反引号的实际不同是什么?MySQL在对这两个符号的操作是怎样的?

求解,谢谢。

回复内容:

注意学习。

Certain objects within MySQL, including database, table, index, column, alias, view, stored procedure, partition, tablespace, and other object names are known as identifiers

An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it.

The identifier quote character is the backtick (“`”):

MySQL :: MySQL 5.5 Reference Manual :: 9.2 Schema Object Names

A string is a sequence of bytes or characters, enclosed within either single quote (“'”) or double quote (“"”) characters
MySQL :: MySQL 5.5 Reference Manual :: 9.1.1 String Literals 最简单的避免错误的方法就是,表名等保留字用反引号,其他例如SQL语句用双引号,我平时就尽量不用单引号的 简单说字符串用单引号,表名,字段名等用反引号
相关标签: MySQL 1.2