简体   繁体   English

在SQL中,我们在哪里使用反引号和引号?

[英]Where do we use backticks and quotes in SQL?

I am new to SQL and still learning but one thing I am confused about is where we use ` and ' operators in SQL. 我是SQL新手,仍然在学习,但令我感到困惑的是,我们在SQL中使用`'运算符的地方。 Can anyone explain this? 谁能解释一下?

Backticks ( ` ) are used to indicate database, table, and column names. 反引号( ` )用于指示数据库,表和列的名称。 Unless you're using reserved or conflicting words for table and database names, you'll not need to use them. 除非为表名和数据库名使用保留字或冲突字,否则将不需要使用它们。

Quotes ( ' or " ) are used to delimit strings, and differentiate them from column names. 用引号( '" )分隔字符串,并将它们与列名区分开。

For example: 例如:

SELECT * FROM `database`.`table` WHERE `column` = "value";

As I mentioned, backticks aren't needed, if you use reasonable table and column names: 如前所述,如果您使用合理的表名和列名,则不需要反引号:

SELECT * FROM mydb.users WHERE username = "jim";

But strings will always need quotes. 但是字符串总是需要用引号引起来。 This query is comparing the value in the column username against a value in the column bob : 此查询将列username中的值与列bob中的值进行比较:

SELECT * FROM mydb.users WHERE username = bob;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM