例如查询是
SELECT `username`, `uid`,`email` from profile and `id`='0';
和
SELECT username, uid,email from profile and id='0';
两者都会产生相同的结果。那么为什么我们应该在mysql查询中使用或不使用`。
反引号将允许您使用 mysql 保留字作为列名。无论如何,这不是一个好主意。
例子:
SELECT from, insert,delete from profile and `id`='0'; will not work
SELECT `from`, `insert`,`delete` from profile and `id`='0'; will work
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.
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!