比较 SQL 和 Prolog [英] Comparing SQL and Prolog

查看:52
本文介绍了比较 SQL 和 Prolog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始学习 Prolog 并想知道与 SQL 语言的理论差异.

I've started learning Prolog and wondering about the theoretical difference from the SQL language.

例如:

  • 两者都是声明性语言
  • 两者都支持事实驱动的知识数据库
  • 都支持问题式数据检索
  • 都支持函数依赖

还有什么共同点?有什么明显的不同吗?

Any more common points? Any notable differences?

推荐答案

这里的大多数(较早的)答案都反映了这样一个事实,即大多数人不知道 SQL 是什么(它是关系微积分的实现)或什么这意味着(它是谓词逻辑的一种形式).以下语句对 Prolog 和 SQL 均适用:

Most of the (earlier) answers here are a reflection of the fact that most people do not know what SQL is (its an implementation of Relational Calculus) or what that means (that it's a form of Predicate Logic). The following statements are true of both Prolog and SQL:

  • 它们都是逻辑驱动的
  • 它们都可以存储、表达和使用关系(Prolog 中的逻辑关系)
  • 它们既可以存储也可以表达复杂的逻辑条件
  • 他们都有事实(SQL 中的数据)并且可以从这些事实中得出结论
  • 他们都有查询,实际上意思是一样的
  • 它们都有数据(Prolog 中的事实)并且使用方法相似
  • 它们都是编程语言
  • 它们都是图灵完备的(尽管在它们两者中都有些难以访问)
  • 等等等等.

一般来说,人们不知道它们之间的这些等价性:

Generally, people are not aware of these equivalences between them:

  1. 事实"和数据"是一回事.这是直接来自 Codd 的原始论文.
  2. 关系理论中的关系"与 SQL 中的表"相同,与谓词逻辑中的关系或关系函数相同,与集合论中的元组集相同
  3. 立>
  4. SQL 中的别名表表达式(即视图等)与 Prolog 中的规则相同.

那么它们的区别是什么?尽管它们在相同的概念域中运作,但它们的侧重点却完全不同.在 Prolog 术语中,SQL 主要是一个事实和关系(集合)引擎,而 Prolog 主要是一个规则和推理引擎.每个人都可以在有限的范围内做另一个,但即使复杂性增加很小,它也会变得越来越困难.例如,您可以在 SQL 中进行推理,但它本质上几乎完全是手动的,完全不像 Prolog 的自动前向推理.是的,您可以在 Prolog 中存储数据(事实),但它根本不是为 SQL 那样的存储、检索、投影和减少具有数千个同时用户的数万亿行"而设计的.

So what are their differences? Although they operate across the same conceptual domains, their focuses are in completely different directions. In Prolog terms, SQL is primarily a Fact and Relation(set) engine, whereas Prolog is primarily a Rules and Inferencing engine. Each can do the other, to a limited extent, but it becomes increasingly difficult with even small increases in complexity. For instance, you can do inferencing in SQL, but it is almost entirely manual in nature and not at all like the automatic forward-inferencing of Prolog. And yes, you can store data(facts) in Prolog, but it is not at all designed for the "storage, retrieval, projection and reduction of Trillions of rows with thousands of simultaneous users" that SQL is.

此外,SQL 主要是一种服务器语言范式,而 Prolog 主要是一种客户端语言范式.

Plus, SQL is primarily a Server-language paradigm, whereas Prolog is primarily a Client-language paradigm.

这篇关于比较 SQL 和 Prolog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆