我的一个专栏叫。我不能改名字,因为不是我做的。 我是否允许做一些像SELECT from TableName或有一个特殊的语法,以避免SQL Server混淆?
当前回答
一些可靠的答案——但投票最多的答案是狭隘的,只涉及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.
在表名上加上冒犯性的单词也可以。
其他回答
在MySQL中,除了使用反引号('),您还可以使用UI来更改列名。右键单击表>修改表>编辑包含sql关键字>提交的列名。
select [from] from <table>
需要注意的是,上述方法在MySQL中不起作用
你的问题似乎已经回答得很好了,但我想再补充一点。
那些设计数据库的人应该很清楚保留的关键字,并避免使用它们。如果你发现有人在使用它,告诉他们(以礼貌的方式)。这里的关键字是保留字。
更多信息:
不应使用保留关键字 作为对象名。数据库升级 从早期版本的SQL Server 可能包含标识符,包括 话不保留在前面 版本,但那是保留的话 SQL Server的当前版本。 可以使用引用对象 分隔标识符直到名称 是可以改变的。” http://msdn.microsoft.com/en-us/library/ms176027.aspx
and
"如果你的数据库确实包含名字 匹配保留关键字,您必须 使用分隔标识符时 引用这些对象。更多的 有关信息,请参见标识符(DMX)。 http://msdn.microsoft.com/en-us/library/ms132178.aspx
一些可靠的答案——但投票最多的答案是狭隘的,只涉及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;因此,查询中的列名可以通过表别名引用
Select * from user u where u.from="US"
在Oracle SQL Developer中,pl/ SQL可以使用双引号,但如果使用双引号,则必须以大写字母输入列名。例如,从MY_TABLE中选择“FROM”
推荐文章
- 如何在Ruby On Rails中使用NuoDB手动执行SQL命令
- 查询JSON类型内的数组元素
- 确定记录是否存在的最快方法
- 获得PostgreSQL数据库中当前连接数的正确查询
- 在SQL选择语句Order By 1的目的是什么?
- 从现有模式生成表关系图(SQL Server)
- 我如何循环通过一组记录在SQL Server?
- 数据库和模式的区别
- 如何在SQL Server中一次更改多个列
- 如何从命令行通过mysql运行一个查询?
- 外键约束可能导致循环或多条级联路径?
- 使用LIMIT/OFFSET运行查询,还可以获得总行数
- 当恢复sql时,psql无效命令\N
- 货币应该使用哪种数据类型?
- 如何选择每一行的列值不是独特的