在SQL语法中,如果您打算使用'where',则从'delete from'中选择'from'是否可选?

时间:2021-07-21 07:25:05

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之间进行调整。这里有一些规则:

  1. Write Scripts manually, don't use generated code
  2. 手动编写脚本,不要使用生成的代码

  3. Allways use INSERT INTO
  4. 总是使用INSERT INTO

  5. Allways DELETE -- without FROM
  6. 永远DELETE - 没有FROM

  7. Don't use " - quoted identifier
  8. 不要使用“ - 引用标识符

  9. Remove all [ ] and dbo.
  10. 删除所有[]和dbo。

  11. Attention when you see DELETE ... FROM ...
  12. 看到DELETE ... FROM时的注意事项......

  13. Attention when you see UPDATE ... FROM ...
  14. 当你看到UPDATE ... FROM时注意......

  15. ORACLE Select statements need a from Clause you can use from DUAL

    ORACLE Select语句需要来自DUAL的Clause

    1. 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
      • USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本

      • SET ANSI_NULLS ON -- decide once which settings to use -- don't switch on and off
      • SET ANSI_NULLS ON - 决定使用哪种设置 - 不要打开和关闭

      • SET QUOTED_IDENTIFIER ON -- quoted identifiers are casesensitive
      • SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写

    2. 好的,您可以编写脚本并以标准方式编辑它们USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本SET ANSI_NULLS ON - 决定使用哪些设置 - 不要打开和关闭SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写

    3. INSERT INTo is required by ORACLE
    4. ORACLE需要INSERT INTo

    5. That is my personal style don't use optinal keyword, learn the defaults
    6. 那是我的个人风格,不要使用optinal关键字,学习默认值

    7. 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
    8. 你必须引用一个标识符,如果你使用ORACLES保留关键字之一作为列nam e,我们输入了这个陷阱,从长远来看,最好重命名sql-Server端的列

    9. ORACLE doesn't use these
    10. ORACLE不使用这些

    11. Oracle doesn't support this syntax
    12. Oracle不支持此语法

    13. Oracle doesn't support this syntax
    14. Oracle不支持此语法

#3


2  

From the Microsoft SQL Server documentation, FROM is optional.

从Microsoft SQL Server文档中,FROM是可选的。

#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之间进行调整。这里有一些规则:

  1. Write Scripts manually, don't use generated code
  2. 手动编写脚本,不要使用生成的代码

  3. Allways use INSERT INTO
  4. 总是使用INSERT INTO

  5. Allways DELETE -- without FROM
  6. 永远DELETE - 没有FROM

  7. Don't use " - quoted identifier
  8. 不要使用“ - 引用标识符

  9. Remove all [ ] and dbo.
  10. 删除所有[]和dbo。

  11. Attention when you see DELETE ... FROM ...
  12. 看到DELETE ... FROM时的注意事项......

  13. Attention when you see UPDATE ... FROM ...
  14. 当你看到UPDATE ... FROM时注意......

  15. ORACLE Select statements need a from Clause you can use from DUAL

    ORACLE Select语句需要来自DUAL的Clause

    1. 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
      • USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本

      • SET ANSI_NULLS ON -- decide once which settings to use -- don't switch on and off
      • SET ANSI_NULLS ON - 决定使用哪种设置 - 不要打开和关闭

      • SET QUOTED_IDENTIFIER ON -- quoted identifiers are casesensitive
      • SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写

    2. 好的,您可以编写脚本并以标准方式编辑它们USE [Current_DB] - 您不希望对测试数据库的引用进入生产脚本SET ANSI_NULLS ON - 决定使用哪些设置 - 不要打开和关闭SET QUOTED_IDENTIFIER ON - 带引号的标识符区分大小写

    3. INSERT INTo is required by ORACLE
    4. ORACLE需要INSERT INTo

    5. That is my personal style don't use optinal keyword, learn the defaults
    6. 那是我的个人风格,不要使用optinal关键字,学习默认值

    7. 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
    8. 你必须引用一个标识符,如果你使用ORACLES保留关键字之一作为列nam e,我们输入了这个陷阱,从长远来看,最好重命名sql-Server端的列

    9. ORACLE doesn't use these
    10. ORACLE不使用这些

    11. Oracle doesn't support this syntax
    12. Oracle不支持此语法

    13. Oracle doesn't support this syntax
    14. Oracle不支持此语法

#3


2  

From the Microsoft SQL Server documentation, FROM is optional.

从Microsoft SQL Server文档中,FROM是可选的。