I am new to SQL. We have some code that should work on SQL Server 2005/2008, Oracle 10 as well as Sybase.
我是SQL的新手。我们有一些代码可以在SQL Server 2005/2008,Oracle 10和Sybase上运行。
I was writing a script to try to figure out which tables a given stored procedure modifies (but does not drop), e.g insert
, update
and delete
.
我正在编写一个脚本来试图找出给定存储过程修改(但不丢弃)的表,例如插入,更新和删除。
The delete
one turned out being puzzling - sometimes I see statements like:
删除一个令人费解 - 有时我看到如下的陈述:
delete phone_book where ...
as opposed to:
而不是:
delete from phone_book where ...
So ... is the from
keyword truly optional in this case? Does this cause any problems? Is it just a bad style, or does it not matter?
那么......在这种情况下,from关键字是否真的是可选的?这会导致任何问题吗?这只是一种不好的风格,还是无所谓?
I have not found a reference to T-SQL
that would make from
optional. I suppose that this is what would unify all 3 vendors I mentioned above.
我没有找到可选的T-SQL引用。我想这可以统一我上面提到的所有3个供应商。
Questions/comments/links are welcomed (or is it welcome?).
欢迎提出问题/意见/链接(或欢迎使用?)。
3 个解决方案
#1
7
At this place the FROM
is optional (SQL Server, Oracle, Sybase).
在这个地方,FROM是可选的(SQL Server,Oracle,Sybase)。
However, there are subtle differences: Oracle for instance allows assigning an alias to the table name, where SQL Server doesn't; and other things are also a little bit different.
但是,存在细微差别:例如,Oracle允许为表名指定别名,而SQL Server则不允许;和其他事情也有点不同。
Also note that your FROM
sample is differnet from the following where it is mandatory:
另请注意,您的FROM示例与强制要求的以下内容不同:
DELETE phone_book FROM some_table WHERE ...
#2
5
Short Answer: Luceros answer is correct: it is optinal
简答:Luceros的回答是正确的:它是选择性的
I have to maintain sql and adapt it between sql-server and Oracle. Here some rules:
我必须维护sql并在sql-server和Oracle之间进行调整。这里有一些规则:
- Write Scripts manually, don't use generated code
- Allways use INSERT INTO
- Allways DELETE -- without FROM
- Don't use " - quoted identifier
- Remove all [ ] and dbo.
- Attention when you see DELETE ... FROM ...
- Attention when you see UPDATE ... FROM ...
-
ORACLE Select statements need a from Clause you can use from DUAL
ORACLE Select语句需要来自DUAL的Clause
- OK you can script your objects and edit them in a standard way
- USE [Current_DB] -- you don't want a reference to your test database go into production script
- SET ANSI_NULLS ON -- decide once which settings to use -- don't switch on and off
- SET QUOTED_IDENTIFIER ON -- quoted identifiers are casesensitive
USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本
SET ANSI_NULLS ON - 决定使用哪种设置 - 不要打开和关闭
SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写
- INSERT INTo is required by ORACLE
- That is my personal style don't use optinal keyword, learn the defaults
- You have to quote an identifier, if you use one of ORACLES reserved keywords as column nam e, we entered that pitfall and in the long run it would have been better to rename the column on the sql-Server side
- ORACLE doesn't use these
- Oracle doesn't support this syntax
- Oracle doesn't support this syntax
好的,您可以编写脚本并以标准方式编辑它们USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本SET ANSI_NULLS ON - 决定使用哪些设置 - 不要打开和关闭SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写
ORACLE需要INSERT INTo
那是我的个人风格,不要使用optinal关键字,学习默认值
你必须引用一个标识符,如果你使用ORACLES保留关键字之一作为列nam e,我们输入了这个陷阱,从长远来看,最好重命名sql-Server端的列
ORACLE不使用这些
Oracle不支持此语法
Oracle不支持此语法
- OK you can script your objects and edit them in a standard way
手动编写脚本,不要使用生成的代码
总是使用INSERT INTO
永远DELETE - 没有FROM
不要使用“ - 引用标识符
删除所有[]和dbo。
看到DELETE ... FROM时的注意事项......
当你看到UPDATE ... FROM时注意......
#3
#1
7
At this place the FROM
is optional (SQL Server, Oracle, Sybase).
在这个地方,FROM是可选的(SQL Server,Oracle,Sybase)。
However, there are subtle differences: Oracle for instance allows assigning an alias to the table name, where SQL Server doesn't; and other things are also a little bit different.
但是,存在细微差别:例如,Oracle允许为表名指定别名,而SQL Server则不允许;和其他事情也有点不同。
Also note that your FROM
sample is differnet from the following where it is mandatory:
另请注意,您的FROM示例与强制要求的以下内容不同:
DELETE phone_book FROM some_table WHERE ...
#2
5
Short Answer: Luceros answer is correct: it is optinal
简答:Luceros的回答是正确的:它是选择性的
I have to maintain sql and adapt it between sql-server and Oracle. Here some rules:
我必须维护sql并在sql-server和Oracle之间进行调整。这里有一些规则:
- Write Scripts manually, don't use generated code
- Allways use INSERT INTO
- Allways DELETE -- without FROM
- Don't use " - quoted identifier
- Remove all [ ] and dbo.
- Attention when you see DELETE ... FROM ...
- Attention when you see UPDATE ... FROM ...
-
ORACLE Select statements need a from Clause you can use from DUAL
ORACLE Select语句需要来自DUAL的Clause
- OK you can script your objects and edit them in a standard way
- USE [Current_DB] -- you don't want a reference to your test database go into production script
- SET ANSI_NULLS ON -- decide once which settings to use -- don't switch on and off
- SET QUOTED_IDENTIFIER ON -- quoted identifiers are casesensitive
USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本
SET ANSI_NULLS ON - 决定使用哪种设置 - 不要打开和关闭
SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写
- INSERT INTo is required by ORACLE
- That is my personal style don't use optinal keyword, learn the defaults
- You have to quote an identifier, if you use one of ORACLES reserved keywords as column nam e, we entered that pitfall and in the long run it would have been better to rename the column on the sql-Server side
- ORACLE doesn't use these
- Oracle doesn't support this syntax
- Oracle doesn't support this syntax
好的,您可以编写脚本并以标准方式编辑它们USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本SET ANSI_NULLS ON - 决定使用哪些设置 - 不要打开和关闭SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写
ORACLE需要INSERT INTo
那是我的个人风格,不要使用optinal关键字,学习默认值
你必须引用一个标识符,如果你使用ORACLES保留关键字之一作为列nam e,我们输入了这个陷阱,从长远来看,最好重命名sql-Server端的列
ORACLE不使用这些
Oracle不支持此语法
Oracle不支持此语法
- OK you can script your objects and edit them in a standard way
手动编写脚本,不要使用生成的代码
总是使用INSERT INTO
永远DELETE - 没有FROM
不要使用“ - 引用标识符
删除所有[]和dbo。
看到DELETE ... FROM时的注意事项......
当你看到UPDATE ... FROM时注意......