在 SQL 中,是“FROM”在“删除自”中如果您打算使用“WHERE”,则可选;
我是 SQL 新手。我们有一些代码应该可以在 SQL Server 2005/2008、Oracle 10 以及 Sybase 上运行。
我正在编写一个脚本来尝试找出给定存储过程修改(但不删除)哪些表,例如 insert
、update
和 delete
。
delete
令人费解 - 有时我会看到这样的语句:
delete phone_book where ...
与:
delete from phone_book where ...
那么 ... 在这种情况下 from
关键字真的是可选的吗?这会导致任何问题吗?这只是一种糟糕的风格,还是无关紧要?
我还没有找到对 T-SQL
的引用,使 from
成为可选。我想这将统一我上面提到的所有 3 个供应商。
欢迎提出问题/评论/链接(或者是否欢迎?)。
I'm new to SQL. We have some code that should work on SQL Server 2005/2008, Oracle 10 as well as 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?
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.
Questions/comments/links are welcomed (or is it welcome?).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在此位置,
FROM
是可选的(SQL Server、Oracle、Sybase)。然而,存在细微的差别:例如,Oracle 允许为表名分配别名,而 SQL Server 则不允许;其他方面也有些不同。
另请注意,您的
FROM
示例与以下强制示例不同:At this place the
FROM
is optional (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.
Also note that your
FROM
sample is differnet from the following where it is mandatory:简短的回答:Luceros 的回答是正确的:它是可选的
,我必须维护 sql 并在 sql-server 和 Oracle 之间进行调整。以下是一些规则:
ORACLE Select 语句需要可以在 DUAL 中使用的 from 子句
Short Answer: Luceros answer is correct: it is optional
I have to maintain sql and adapt it between sql-server and Oracle. Here are some rules:
ORACLE Select statements need a from clause you can use from DUAL
从 Microsoft SQL Server 文档来看,FROM 是可选的。
From the Microsoft SQL Server documentation, FROM is optional.
在SQL Server中,
DELETE FROM
的FROM
是可选的,没有FROM
的DELETE
是不是SQL 标准,而DELETE FROM
是SQL 标准。我在 SQL Server、MySQL、<如下图所示:
另外我还实验了
INSERT INTO
以及在 SQL Server、MySQL、PostgreSQL 和 上不使用INTO
的INSERT
SQLite 如下所示。In SQL Server,
FROM
ofDELETE FROM
is optional andDELETE
withoutFROM
is not SQL standard whileDELETE FROM
is SQL standard.I experimented
DELETE FROM
andDELETE
withoutFROM
on SQL Server, MySQL, PostgreSQL and SQLite as shown below:In addition, I also experimented
INSERT INTO
andINSERT
withoutINTO
on SQL Server, MySQL, PostgreSQL and SQLite as shown below.在这三个 DBMS 中,
from
在delete from
中是可选的,但根据 SQL 标准,它是强制性的。我总是使用delete from
来简化 SQL 代码从一个 DBMS 到另一个 DBMS 的迁移。from
is optional indelete from
in those three DBMSes but it is mandatory according to the SQL standard. I would always usedelete from
to ease the migration of SQL code from one DBMS to another.