在哪里可以获得 RDBMS 查询的 ANSI 或 ISO 标准?

发布于 2024-09-08 06:34:05 字数 75 浏览 3 评论 0原文

我想编写一些可以在几乎所有数据库中运行而没有任何 SQLExceptions 的查询。那么,我在哪里可以获得 ANSI 标准来编写查询?

I want to write some queries which can work in almost all the databases without any SQLExceptions. So, where can I get the ANSI standards to write the queries ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

没企图 2024-09-15 06:34:05

不确定这会对你有帮助。

供应商在标准实现方面很敏感,而且标准本身通常不够精确,因此您永远无法编写适用于所有实现者的查询。

例如,SQL 92 将连接运算符定义为 ||,但 MySQL 和 MSSQL 都没有使用它(Oracle 这样做)。独立于供应商的字符串连接是不可能的。

同样,未指定标准转义字符,因此您的处理方式可能不适用于所有供应商。

话虽如此:

Not sure that'll help you.

Vendors are touch and go as far as standards implementation and often the standards themselves are imprecise enough such that you could never write a query that would work with all implementors.

For example, SQL 92 defines the concatenation operator as || but neither MySQL nor MSSQL use this (Oracle does). Vendor independent string concatenation is impossible.

Similarly, a standard escape character is not specified so how you handled that might not work in all vendors.

Having said that:

友谊不毕业 2024-09-15 06:34:05

来自 维基百科

SQL 标准不是免费提供的。整个标准可以从 ISO 购买,即 ISO/IEC 9075(1-4,9-11,13,14):2008。

不过,我不建议您遵循此策略,因为没有数据库引擎严格遵循任何 SQL 标准(SQL 99、2003 等)。它们都在处理指令或定义变量的方式上采取了自由(例如,当比较两个字符串时,不同的引擎以不同的方式处理区分大小写)。对于一种引擎来说非常有效的方法对于另一种引擎来说可能效率非常低。

建议开发一组标准查询并开发不同的类,其中包含针对特定目标 RDBMS 的查询的特定实现。

希望这有帮助

From wikipedia:

The SQL standard is not freely available. The whole standard may be purchased from the ISO as ISO/IEC 9075(1-4,9-11,13,14):2008.

Nevertheless I would not advise you to follow this strategy because no database engine follows any SQL standard (SQL 99, 2003, etc.) to the letter. All of them take liberties in the way they handle instructions or define variables (for example, when comparing two strings different engines handle case sensitivity differently). A method that is very efficient with one engine can be terrible inefficient for another.

A suggestion would be to develop a standard group of queries and develop different classes that contain the specific implementation of that query for a certain target RDBMS.

Hope this helped

倒带 2024-09-15 06:34:05

查看核心 SQL 语法的 BNF,网址为 http://savage.net.au/SQL/

这是答案的一部分 - 其余的,正如 Kiranu 和 MattMitchell 指出的那样,是不同的供应商以不同的方式实现该标准。没有任何 DBMS 能够完美地遵循 SQL-92,尽管大多数都非常接近。

一项观察:SQL 标准没有提及索引 - 因此没有用于创建索引的标准语法。它也没有提及如何创建数据库;每个供应商都有自己的机制来做到这一点。

Check out the BNF of the core SQL grammars available at http://savage.net.au/SQL/

This is part of the answer - the rest, as pointed out by Kiranu and MattMitchell, is that different vendors implement the standard differently. No DBMS adheres perfectly to even SQL-92, though most are pretty close.

One observation: the SQL standard says nothing about indexes - so there is no standard syntax for creating an index. It also says nothing about how to create a database; each vendor has their own mechanisms for doing that.

二手情话 2024-09-15 06:34:05

Sql-92 标准 可能就是您想要的目标。我相信它支持大多数主要的 RDBMS。

这是一个不太简洁的链接。示例内容:

  • PostgreSQL 有视图。不允许更新视图,从而违反了标准...
  • DB2 至少符合 SQL-92。
  • MSSQL 至少符合 SQL-92。
  • MySQL 至少符合 SQL-92。
  • Oracle 至少符合 SQL-92。
  • Informix 至少符合 SQL-92。

如果您使用 .NET,您可能会考虑使用 System.Data.Common 中的工厂模式可以很好地抽象许多 RDBMS 的提供者细节。

The Sql-92 standard is probably the one you want to target. I believe it's supported most of the major RDBMSs.

Here is a less terse link. Sample content:

  • PostgreSQL Has views. Breaks standard by not allowing updates to views...
  • DB2 Conforms to at least SQL-92.
  • MSSQL Conforms to at least SQL-92.
  • MySQL Conforms to at least SQL-92.
  • Oracle Conforms to at least SQL-92.
  • Informix Conforms to at least SQL-92.

Something else you might consider, if you're using .NET, is to use the factory pattern in System.Data.Common which does a good job of abstracting provider specifics for a number of RDBMSs.

昇り龍 2024-09-15 06:34:05

如果您正在尝试制作一款可用于多个数据库的产品,我认为尝试仅使用标准 sql 并不是正确的方法,正如其他答案所表明的那样,由于标准的“解释”不同。相反,如果可能的话,您应该在应用程序中拥有某种数据访问层,该层针对每个数据库具有特定的不同实现。根据您想要做什么,有一些工具(例如 Hibernate)可以为您完成许多繁重的工作。

If you are trying to make a product that will work against multiple databases I think trying to only use standard sql is not the way to go, as other answers have indicated, due to the different 'interpretations' of the standard. Instead you should if possible have some kind of data access layer in your application which has different implementations specific for each database. Depending on what you are trying to do, there are tools such as Hibernate which will so a lot of the heavy lifting in regards to this for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文