Giáo trình SQL Bài 10
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Giáo trình SQL Bài 10 Lecture 4The Relational Algebra and Relational Calculus – 1 Objectives • Relational Algebra § Unary Relational Operations § Relational Algebra Operations From Set Theory • Reference: Chapter 6Faculty of Science and Technology Database Fundamentals 2 Review Relational Database Model • Database: relations (tables) • Relation: attributes (columns) – tuples (rows) • Attribute: domain (data type)Faculty of Science and Technology Database Fundamentals 3 Relational Algebra Overview • Relational algebra is the basic set of operations for the relational model • These operations enable a user to specify basic retrieval requests (or queries) • The result of an operation is a new relation, which may have been formed from one or more input relations § This property makes the algebra “closed” (all objects in relational algebra are relations) • A sequence of relational algebra operations forms a relational algebra expression § The result of a relational algebra expression is also a relation that represents the result of a database query (or retrieval request)Faculty of Science and Technology Database Fundamentals 4 Relational Algebra Overview • Relational Algebra consists of several groups of operations § Unary Relational Operations • SELECT (σ (sigma)) • PROJECT (π (pi)) • RENAME (ρ (rho)) § Relational Algebra Operations From Set Theory • UNION ( ∪ ), INTERSECTION ( ∩ ), DIFFERENCE (or MINUS, – ) • CARTESIAN PRODUCT ( x ) § Binary Relational Operations (next session) • JOIN (several variations of JOIN exist) • DIVISION § Additional Relational Operations (next session) • OUTER JOINS, OUTER UNION • AGGREGATE FUNCTIONS (These compute summary of information: for example, SUM, COUNT, AVG, MIN, MAX)Faculty of Science and Technology Database Fundamentals 5 Database State for COMPANY • All examples discussed below refer to the COMPANY database shown here.Faculty of Science and Technology Database Fundamentals 6 Database State for COMPANYFaculty of Science and Technology Database Fundamentals 7 Unary Relational Operations: SELECT • The SELECT operation (σ) is used to select a subset of the tuples from a relation based on a selection condition. § The selection condition acts as a filter § Keeps only those tuples that satisfy the qualifying condition § Tuples satisfying the condition are selected whereas the other tuples are discarded (filtered out) • Examples: § Select the EMPLOYEE tuples whose department number is 4: σ Dno = 4 (EMPLOYEE) § Select the employee tuples whose salary is greater than $30,000: σ Salary > 30,000 (EMPLOYEE)Faculty of Science and Technology Database Fundamentals 8 Unary Relational Operations: SELECT (2) § In general, the select operation is denoted by σ (R) where • the symbol σ (sigma) is used to denote the select operator • the selection condition is a Boolean (conditional) expression specified on the attributes of relation R • tuples that make the condition true are selected § appear in the result of the operation • tuples that make the condition false are filtered out § discarded from the result of the operationFaculty of Science and Technology Database Fundamentals 9 Unary Relational Operations: SELECT (3) • SELECT Operation Properties § The SELECT operation σ (R) produces a relation S that has the same schema (same attributes) as R § SELECT σ is commutative: • σ (σ < condition2> (R)) = σ (σ < condition1> (R)) • σ (σ (σ (R))) = σ (σ (σ ( R))) § Conjunction of all the conditions: • σ (σ < cond2> (σ (R))) = σ AND < cond2> AND < cond3>(R) § The number of tuples in the result of a SELECT is less than (or equal to) the number of tuples in the input relation RFaculty of Science and Technology Database Fundamentals 1 ...
Gợi ý tài liệu liên quan:
-
62 trang 402 3 0
-
Đề thi kết thúc học phần học kì 2 môn Cơ sở dữ liệu năm 2019-2020 có đáp án - Trường ĐH Đồng Tháp
5 trang 378 6 0 -
13 trang 296 0 0
-
Giáo trình Cơ sở dữ liệu: Phần 2 - TS. Nguyễn Hoàng Sơn
158 trang 294 0 0 -
Phân tích thiết kế hệ thống - Biểu đồ trạng thái
20 trang 290 0 0 -
Tài liệu học tập Tin học văn phòng: Phần 2 - Vũ Thu Uyên
85 trang 258 1 0 -
Đề cương chi tiết học phần Quản trị cơ sở dữ liệu (Database Management Systems - DBMS)
14 trang 248 0 0 -
Giáo trình về dữ liệu và các mô hình cơ sở dữ liệu
62 trang 187 0 0 -
8 trang 186 0 0
-
Giáo trình Cơ sở dữ liệu: Phần 2 - Đại học Kinh tế TP. HCM
115 trang 176 0 0 -
Bài giảng môn học Cơ sở dữ liệu - Chương 1: Tổng quan về cơ sở dữ liệu
27 trang 171 0 0 -
Giáo trình Cơ sở dữ liệu: Phần 1 - Sở Bưu chính Viễn Thông TP Hà Nội
48 trang 171 1 0 -
Bài giảng Cấu trúc dữ liệu và thuật toán: Chương 7 - Nguyễn Khánh Phương
214 trang 160 0 0 -
Báo cáo Thực tập chuyên môn Thiết kế cơ sở dữ liệu: Xây dựng Website studio
26 trang 155 0 0 -
Hướng dẫn tạo file ghost và bung ghost
12 trang 155 0 0 -
Giáo trình Nhập môn Cơ sở dữ liệu - GV. Nguyễn Thế Dũng
280 trang 154 0 0 -
Bài tập thiết kế cơ sở dữ liệu
9 trang 146 0 0 -
Bài giảng Cơ sở dữ liệu (Database) - Chương 2: Mô hình thực thể - liên kết
120 trang 140 0 0 -
Vai trò của phân tích, thiết kế hệ thống thông tin trong quy trình xây dựng phần mềm
7 trang 135 0 0 -
204 trang 129 1 0