我的一个专栏叫。我不能改名字,因为不是我做的。 我是否允许做一些像SELECT from TableName或有一个特殊的语法,以避免SQL Server混淆?


当前回答

当你这样做的时候,把它别名为其他东西(或者更好的是,使用一个视图或SP并弃用旧的直接访问方法)。

SELECT [from] AS TransferFrom -- Or something else more suitable
FROM TableName

其他回答

将列名像这样用括号括起来,from变成[from]。

select [from] from table;

也可以使用以下命令(在查询多个表时很有用):

select table.[from] from table;

简单的解决方案

假设列名是from;因此,查询中的列名可以通过表别名引用

Select * from user u where u.from="US"

在Apache Drill中,使用反引号:

select `from` from table;

如果您正在使用SQL Server,您可以简单地将方括号括在列名或表名周围。

select [select]
from [table]

当你这样做的时候,把它别名为其他东西(或者更好的是,使用一个视图或SP并弃用旧的直接访问方法)。

SELECT [from] AS TransferFrom -- Or something else more suitable
FROM TableName