数据库 sql和关系代数

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/cuidiwhere/article/details/79576118

疑惑:在数据库理论学习中,会学到关系代数(Relational Algebra),为什么要学它? 它和sql语言有什么关系?

看完参考资料后,我的总结:

1. What is Relational Algebra?

From wiki: 

Relational algebra, first created by Edgar F. Codd while at IBM, is a family of algebras with a well-founded semantics used for modelling the data stored in relational databases, and defining queries on it.

The main application of relational algebra is providing a theoretical foundation for relational databases, particularly query languages for such databases, chief among which is SQL.

From [2]

RA is similar to normal algebra (as in 2+3*x-y), except we use relations as values instead of numbers, and the operations and operators are different.

RA is not used as a query language in actual DBMSs. (SQL instead.)


2. Why? 

  • The inner, lower-level operations of a relational DBMS are, or are similar to, relational algebra operations. We need to know about relational algebra to understand query execution and optimization in a relational DBMS.


3. RA vs. SQL

1. duplicates

Relations are seen as sets of tuples, which means that no duplicates are allowed. SQL behaves differently in some cases. Remember the SQL keyword distinct.

2. procedural? declarative

SQL is declarative, which means that you tell the DBMS what you want, but not how it is to be calculated. 

A C++ or Java program is procedural, which means that you have to state, step by step, exactly how the result should be calculated. 

Relational algebra is (more) procedural than SQL. (Actually, relational algebra is mathematical expressions.)


参考资料

1. https://en.wikipedia.org/wiki/Relational_algebra

2. http://www.databasteknik.se/webbkursen/relalg-lecture/index.html 

3.https://www.quora.com/What-is-the-difference-or-connection-between-SQL-and-Relational-Algebra

5.http://www.nyu.edu/classes/jcf/CSCI-GA.2433-001/slides/session5/RelationalAlgebra-RelationalCalculus-SQL.pdf

6. http://www.cs.cornell.edu/projects/btr/bioinformaticsschool/slides/gehrke.pdf

猜你喜欢

转载自blog.csdn.net/cuidiwhere/article/details/79576118