是否有适用于所有数据库的标准sql

发布于 2024-08-18 11:07:12 字数 319 浏览 1 评论 0原文

如下所示,不同数据库的语法有所不同。是否存在适用于所有数据库的标准方法。 有没有任何工具可以将任何sql转换为任何sql

SqlServer2005:

 CREATE TABLE Table01 (  
 Field01  int  primary key identity(1,1)  
 )

Sqlite:

CREATE TABLE Table01 (
  Field01  integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE
);

As seen below the syntax is different for different Database .Isnt there a standard way that works in all Databases.
Is there any tool to convert any sql to any sql

SqlServer2005:

 CREATE TABLE Table01 (  
 Field01  int  primary key identity(1,1)  
 )

Sqlite:

CREATE TABLE Table01 (
  Field01  integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE
);

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

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

发布评论

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

评论(3

七婞 2024-08-25 11:07:12

SQL 的“查询”部分(通常称为 DML - 数据操作语言)已相当标准化,如果不使用“供应商增强”功能,在一个数据库上编写的查询通常会在另一个数据库上运行。 SQL 的“创建数据库位”部分(通常称为 DDL - 数据定义语言)并未标准化,并且每个数据库的做法都略有不同。因此,正如您所发现的,如果不对另一个数据库进行一些调整,为一个数据库编写的诸如 CREATE TABLE 之类的语句将无法工作。


在我看来,这是一件好事。 DDL 有效地定义了可以在数据库中创建的内容。如果所有供应商都使用完全相同相同的 DDL,那么所有产品在其支持的功能方面都将完全相同相同。例如,为了允许在 PostgreSQL 中进行表继承,必须有某种方法来定义一个表如何从另一个表继承,并且此定义必须是表定义方式的一部分,可以是 CREATE TABLE 语句的一部分,也可以是某些表的一部分。其他时尚,但它必须是 DDL 语句。因此,出于纯粹的功能原因(因为 PostgreSQL 支持大多数数据库不支持的功能),PostgreSQL 中的 DDL 必须与其他数据库不同。 MySQL 中也出现了类似的情况,因为它允许使用具有不同功能的不同 ISAM 引擎。类似的情况也出现在 Oracle...和 ​​SQL Server...以及<此处是您最喜欢的数据库> 中。

标准是一把双刃剑。一方面,它们是一件很棒的事情,因为它们提供了一种“标准”的做事方式。另一方面,它们是一件可怕的事情,因为标准的真正目的是提供一种“标准”的做事方式,这是“造成停滞并抑制创新”的另一种说法。

分享并享受。

The "query" part of SQL (commonly called DML - Data Manipulation Language) is reasonably standardized, and queries written on one database will often run on another database if no "vendor enhancement" features are used. The "create database bits" parts of SQL (often known as DDL - Data Definition Language) is not standardized, and every database out there does it a little differently. So, as you've discovered, statements such as CREATE TABLE written for one database will not work without some tweaking on another database.

<soapbox>
In my opinion this is a Good Thing. DDL effectively defines what can be created in the database. If all vendors use exactly the same DDL, then all products are going to be exactly the same in terms of the features they support. For example, in order to allow for table inheritance in PostgreSQL there must be some way to define how one table inherits from another, and this definition must be part of how a table is defined, either as part of the CREATE TABLE statement or in some other fashion, but it has to be a DDL statement. Thus, for purely functional reasons (because PostgreSQL supports a feature which most databases do not) DDL in PostgreSQL must be different than in other databases. A similar situation arises in MySQL because it allows the use of different ISAM engines with different capabilities. Similar situations arise in Oracle...and in SQL Server...and <your favorite database here>.

Standards are a double-edged sword. One one hand they're a great thing, because they provide a "standard" way of doing something. On the other hand they're a terrible thing because the very purpose of a standard is to provide a "standard" way of doing something, which is another way of saying "create stagnation and inhibit innovation".
</soapbox>

Share and enjoy.

万劫不复 2024-08-25 11:07:12

几个 SQL 标准,并且 SQL 1999 可能是您能得到的最接近的,因为每个数据库都采用不同的标准(如果有的话)。

There are several SQL standards out there, and SQL 1999 is probably the closest you will get, as each DB adopted a different standard (if any).

三生殊途 2024-08-25 11:07:12

不,没有用于此的标准 SQL。作为一个无耻的插件,如果您对相关内容感兴趣,我建议尝试 Wizardby数据库模式迁移/持续集成。

No, there's no standard SQL for this. As a shameless plug, I can recommend trying Wizardby if you're into anything related to database schema migration/continuous integration.

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