0

例如查询是

SELECT `username`, `uid`,`email` from profile  and `id`='0';

SELECT username, uid,email from profile  and id='0';

两者都会产生相同的结果。那么为什么我们应该在mysql查询中使用或不使用`。

4

3 回答 3

0

反引号将允许您使用 mysql 保留字作为列名。无论如何,这不是一个好主意。

例子:

SELECT from, insert,delete from profile  and `id`='0'; will not work

SELECT `from`, `insert`,`delete` from profile  and `id`='0'; will work
于 2013-08-05T14:11:10.340 回答
0

The backtick and nonbacktick versions that you show both do the same thing.

The main reason one would use backticks is to escapse a MySQL reserved word or a column with a space in the column name.

于 2013-08-05T13:41:23.660 回答
0

You can name your columns anything if you use ` to delimit them. You could call it timestamp, restrict or any other keyword. Or you could call it 60000. Or you could call it domain of the flying spaghetti monster if you really wanted.

SELECT `domain of the flying spaghetti monster` FROM `table`

has to be the weirdest select query I've seen!

于 2013-08-05T13:41:25.990 回答