CS 425 – Database Organization - 3 - Chapter 3 :Formal Relational Query Language (1)

本文详细介绍了关系型查询语言,包括关系代数的基础概念、表达能力、选择、投影、并集、差集、笛卡尔积等操作。通过实例展示了如何使用这些操作进行数据库查询,并探讨了外连接、自然连接、分配操作、聚合函数等进阶主题。
摘要由CSDN通过智能技术生成

1、Relational Query Language

① Expressive power of a query language

  • What queries can be expressed in this language?

② Procedural versus non-procedural, or declarative
③ “Pure” languages:

  • Relational algebra
  • Tuple relational calculus
  • Domain relational calculus

④ The above 3 pure languages are equivalent in computing power
⑤ Relational algebra:

  • Algebra of relations -> set of operators that take relations as input and produce relations as output
  • -> composable: the output of evaluating an expression in relational algebra can be used as input to another relational algebra expression

⑥Now: First introduction to operators of the relational algebra

2、Relational Algebra

① Procedural language
② Six basic operators

  • select: σ
  • project: π
  • union: ∪
  • set difference: –
  • Cartesian product: x
  • rename: ρ

③ The operators take one or two relations as inputs and produce a new relation as a result.

  • composable

3、Select operation
① Notation: σ ρ(r )
② ρ is called the selection predicate‘
③ Defined as:
在这里插入图片描述
④ Where ρ is a formula in propositional calculus consisting of terms connected by :
<1> ∧ (and), ∨ (or), ¬ (not)
<2>Each term is one of:
<attribute> op <attribute> or <constant>
<3>where op is one of: =, ≠, >, ≥,<,≤
⑤ Example
在这里插入图片描述
4、Select Operation - Example
在这里插入图片描述

σ dept_name=“Physics”(instructor )

在这里插入图片描述
5、Project Operation

① Notation:
在这里插入图片描述
πA 1,A 2,......, Ak(r)
② where A1, A2 are attribute names and r is a relation name.
③The result is defined as the relation of k columns obtained by erasing the columns that are not listed
④ Duplicate rows removed from result, since relations are sets
⑤ Let A be a subset of the attributes of relation r then:
在这里插入图片描述
⑥ Example: To eliminate the dept_name attribute of instructor
在这里插入图片描述

6、Project Operation - Example
在这里插入图片描述
在这里插入图片描述
7、Union operation
① Notation: r ∪ s
② Defined as:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值