I am new to SQL and still learning but one thing I am confused about is where we use `
and '
operators in SQL. Can anyone explain this?
我对SQL还不熟悉,但有一件事我很困惑,那就是我们在SQL中使用“和”操作符的地方。谁能解释这个?
1 个解决方案
#1
4
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
:
但是字符串总是需要引号。该查询将列用户名中的值与列bob中的值进行比较:
SELECT * FROM mydb.users WHERE username = bob;
#1
4
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
:
但是字符串总是需要引号。该查询将列用户名中的值与列bob中的值进行比较:
SELECT * FROM mydb.users WHERE username = bob;