I've started learning Prolog and wondering about the theoretical difference from the SQL language.
For example:
- both are declarative languages
- both support a fact-driven knowledge database
- both support question-styled data-retrieving
- both support functional dependencies
Any more common points? Any notable differences?
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:
Generally, people are not aware of these equivalences between them:
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.
Plus, SQL is primarily a Server-language paradigm, whereas Prolog is primarily a Client-language paradigm.
There are many differences which I think become clear when you start using them. Remember because of changes in terminology, somethings which are called the same thing in the past mean very different things now.
Very broad overview of difference.
SQL statements work against a relational database and query (ask for) data from that database, changes to that data and the results are exactly expressed in the language, whereas in Prolog you define facts and a logic engine generates new facts based off of the existing facts. New data (facts) are created via evaluation.
They both use something called queries (but they work totally differently) and they both have data (but use it differently.)
The use cases for SQL and Prolog are also totally different. It would never make sense to store an address list in Prolog whereas that is exactly what SQL was designed to do.
Simply put SQL is used to access a data store and Prolog is an expression evaluator.
The main difference in my eyes is that SQL retrieves rows from tables - that is, from a finite set of instantiated objects corresponding to certaing filter conditions. On the other hand, Prolog gives you theoretically all the instantiable objects that satisfy the conditions. And while in Prolog you can also retrieve entities from a finite set, in SQL you can't fetch all the values from a theoretically infinite set.
xonix, you need more development experience to say whether something can be done in sql or not.
Below are at least 2 solutions for your fibo series. One using
Stored Procedure
and the other usingCTE
. Take your pick.METHOD 1
METHOD 2
Just a few thoughts:
I think the main difference is that Prolog is a query language used for matching complicated patterns against a database of simple facts. SQL on the other hand is limited to relational databases.