SQL SQL标准转义列名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2901453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL standard to escape column names?
提问by
Is there a SQL standard to escape a column name? If not what works for mysql and sqlite? does it also work for sqlserver?
是否有 SQL 标准来转义列名?如果不是什么适用于 mysql 和 sqlite?它也适用于 sqlserver 吗?
回答by Dean Harding
Quotation Mark "
引号 "
The SQL:1999standard specifiesthat double quote (") (QUOTATION MARK) is used to delimit identifiers.
在SQL:1999标准指定的是双引号(“)(引号)来界定标识符。
<delimited identifier> ::= <double quote> <delimited identifier body> <double quote>
Oracle, PostgreSQL, MySQL, MSSQL and SQlite all support "
as the identifier delimiter.
Oracle、PostgreSQL、MySQL、MSSQL 和 SQlite 都支持"
作为标识符分隔符。
They don't all use "
as the 'default'. For example, you have to be running MySQL in ANSI modeand SQL Server only supports it when QUOTED_IDENTIFIER
is ON
.
它们并不都"
用作“默认”。例如,你必须要运行MySQL ANSI模式下,当SQL Server只支持它QUOTED_IDENTIFIER
的ON
。
回答by tc.
According to SQLite,
根据SQLite,
'foo'
is an SQL string"foo"
is an SQL identifier (column/table/etc)[foo]
is an identifier in MS SQL`foo`
is an identifier in MySQL
'foo'
是一个 SQL 字符串"foo"
是 SQL 标识符(列/表/等)[foo]
是 MS SQL 中的标识符`foo`
是 MySQL 中的标识符
For qualified names, the syntax is: "t"."foo"
or [t].[foo]
, etc.
对于限定名称,语法为:"t"."foo"
or[t].[foo]
等。
MySQL supports the standard "foo" when the ANSI_QUOTES
option is enabled.
ANSI_QUOTES
启用该选项时,MySQL 支持标准的“foo” 。
回答by Kerry Jones
For MySQL, use back ticks `.
对于 MySQL,使用反勾号`。
For instance:
例如:
SELECT `column`, `column2` FROM `table`
回答by BoltBait
For MS SQL use [ and ]
对于 MS SQL 使用 [ 和 ]
SELECT [COLUMN], [COLUMN 2] FROM [TABLE]
回答by Serhii Matrunchyk
For DBASE/DBF use [
and ]
用于 DBASE/DBF[
和]
SELECT [DATE], [TIME], [ANY_OTHER_TO_BE_ESCAPED_COLUMN] FROM [TABLE]
回答by orangecaterpillar
Putting some answers together:
把一些答案放在一起:
MS SQL (a.k.a T-SQL), Microsoft Access SQL, DBASE/DBF: SELECT [COLUMN], [COLUMN2] FROM [TABLE]
MS SQL(又名 T-SQL)、Microsoft Access SQL、DBASE/DBF: SELECT [COLUMN], [COLUMN2] FROM [TABLE]
MySQL: SELECT `COLUMN`, `COLUMN2` FROM `TABLE`
MySQL: SELECT `COLUMN`, `COLUMN2` FROM `TABLE`
SQLite, Oracle, Postgresql: SELECT "COLUMN", "COLUMN2" FROM "TABLE"
SQLite、Oracle、Postgresql: SELECT "COLUMN", "COLUMN2" FROM "TABLE"
Please add/edit!
请添加/编辑!