我的一个专栏叫。我不能改名字,因为不是我做的。 我是否允许做一些像SELECT from TableName或有一个特殊的语法,以避免SQL Server混淆?
当前回答
嗨,我在完全符合ANSI标准的Teradata系统上工作。使用双引号“”来命名这样的列。
例如,type是一个SQL保留关键字,当在引号中使用时,type被视为用户指定的名称。
参见下面的代码示例:
CREATE TABLE alpha1
AS
(
SEL
product1
type_of_product AS "type"
FROM beta1
) WITH DATA
PRIMARY INDEX (product1)
--type is a SQL reserved keyword
TYPE
--see? now to retrieve the column you would use:
SEL "type" FROM alpha1
其他回答
下面的方法会很有效:
SELECT DISTINCT table.from AS a FROM table
一些可靠的答案——但投票最多的答案是狭隘的,只涉及SQL Server。总而言之:
If you have source control, the best solution is to stick to the rules, and avoid using reserved words. This list has been around for ages, and covers most of the peculiarities. One tip is that reserved words are rarely plural—so you're usually safe using plural names. Exceptions are DIAGNOSTICS, SCHEMAS, OCTETS, OFFSETS, OPTIONS, VALUES, PARAMETERS, PRIVILEGES and also verb-like words that also appear plural: OVERLAPS, READS, RETURNS, TRANSFORMS. Many of us don't have the luxury of changing the field names. There, you'll need to know the details of the RDBM you're accessing: For SQL Server use [square_braces] around the name. This works in an ODBC connection too. For MySQL use `back_ticks`. Postgres, Oracle and several other RDBMs will apparently allow "double_quotes" to be used.
在表名上加上冒犯性的单词也可以。
将列名像这样用括号括起来,from变成[from]。
select [from] from table;
也可以使用以下命令(在查询多个表时很有用):
select table.[from] from table;
在MySQL中,除了使用反引号('),您还可以使用UI来更改列名。右键单击表>修改表>编辑包含sql关键字>提交的列名。
select [from] from <table>
需要注意的是,上述方法在MySQL中不起作用
以下是两种方法:
使用后面的引用如下:
从表名中选择“from”
你可以用表名提到:
SELECT TableName. FROM FROM TableName