Bài giảng Hệ quản trị cơ sở dữ liệu - Chương 7: Ngôn ngữ SQL
Số trang: 64
Loại file: pptx
Dung lượng: 1.72 MB
Lượt xem: 27
Lượt tải: 0
Xem trước 7 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Bài giảng Hệ quản trị cơ sở dữ liệu - Chương 7 giới thiệu về ngôn ngữ SQL. Chương này trình bày một số nội dung cơ bản như: Câu truy vấn cơ bản; union, intersect, and except; nested queries;...và một số nội dung khác, mời các bạn cùng tham khảo.
Nội dung trích xuất từ tài liệu:
Bài giảng Hệ quản trị cơ sở dữ liệu - Chương 7: Ngôn ngữ SQL Chapter7NgônngữSQL(StructuredQueryLanguage) 1 2 Ví dụ• Cho một cơ sở dữ liệu gồm các quan hệ Sailors, Reserves và Boats. – Sailors(sid: integer, sname: string, rating: integer , age: real) – Boats(bid: integer, bname: string, color: string) – Reserves(sid: integer , bid: integer , day: date) 3Ví dụ 4 Câu truy vấn cơ bản• Cú pháp – SELECT: chỉ định các cột xuất hiện trong kết quả. – FROM: xác định các bảng trong câu truy vấn – WHERE: tùy chọn, chỉ định điều kiện chọn ra các dòng trên các bảng trong mệnh đề 5 Câu truy vấn cơ bản– From-list: tên của các quan hệ.– Select-list: danh sách các thuộc tính của các quan hệ trong from-list– Qualification: Các phép so sánh • , =, ≤, ≥, , AND, OR, NOT.– DISTINCT: loại bỏ các giá trị trùng trong kết quả. 6 Câu truy vấn cơ bản• Conceptual Evaluation Strategy: – Semantics of an SQL query defined in terms of the following conceptual evaluation strategy: • Compute the cross-product of relation-list. • Discard resulting tuples if they fail qualifications. • Delete attributes that are not in target-list. • If DISTINCT is specified, eliminate duplicate rows. 7 Câu truy vấn cơ bản• A Note on Range Variables – Really needed only if the same relation appears twice in the FROM clause. SELECTS.sname FROMSailorsS,ReservesR WHERES.sid=R.sidANDbid=103 SELECTsname FROMSailors,Reserves WHERESailors.sid=Reserves.sidANDbid=103 8 Câu truy vấn cơ bản• Examples of Basic SQL Queries – Find the names and ages of all sailors. – Find the names and ages of all sailors 9 Câu truy vấn cơ bản– Find all sailors with a rating above 7.– When you want to retrieve all columns: 10 Câu truy vấn cơ bản– Find the sids of sailors who have reserved a red boat.– Find the names of sailors who have reserved a red boat. 11 Câu truy vấn cơ bản– Find the colors of boats reserved by Lubber– Find the names of sailors who have reserved at least one boat. 12 5.2 The Form of A Basic SQL Query• Expressions and Strings in the SELECT Command – Select-list: • Can be of the form expression AS column name, where expression is any arithmetic or string expression over column names and constants. • It can also contain aggregates such as sum and count. 13 Câu truy vấn cơ bản– Ex: Compute increments for the ratings of persons who have sailed two different boats on the same day 145.2 The Form of A Basic SQL Query– Find triples (of ages of sailors and two fields defined by expressions) for sailors whose names begin and end with B and contain at least three characters. SELECTS.age,age1=S.age5,2*S.ageASage2 FROMSailorsS WHERES.snameLIKE‘B_%B’ 15 Câu truy vấn cơ bản• String Comparisons – LIKE is used for string matching. – “_” stands for any one character and – “%”stands for 0 or more arbitrary characters Ex: Find the ages of sailors whose name begins and ends with B and has at least three characters. 16 Union, Intersect, And Except• UNION: – s1 UNION s2, result rows either in s1 or s2.• INTERSECT: – s1 INTERSECT s2, result rows in s1 and s2.• EXCEPT: – s1 EXCEPT s2, result rows in s1 but not in s2. (Some system recognize ‘MINUS’ for EXECPT)• IN, ANY, ALL, EXISTS to be covered in ‘Nested Queries’. 17Union, Intersect, And Except– Find the names of sailors who have reserved a red or a green boat 18Uni ...
Nội dung trích xuất từ tài liệu:
Bài giảng Hệ quản trị cơ sở dữ liệu - Chương 7: Ngôn ngữ SQL Chapter7NgônngữSQL(StructuredQueryLanguage) 1 2 Ví dụ• Cho một cơ sở dữ liệu gồm các quan hệ Sailors, Reserves và Boats. – Sailors(sid: integer, sname: string, rating: integer , age: real) – Boats(bid: integer, bname: string, color: string) – Reserves(sid: integer , bid: integer , day: date) 3Ví dụ 4 Câu truy vấn cơ bản• Cú pháp – SELECT: chỉ định các cột xuất hiện trong kết quả. – FROM: xác định các bảng trong câu truy vấn – WHERE: tùy chọn, chỉ định điều kiện chọn ra các dòng trên các bảng trong mệnh đề 5 Câu truy vấn cơ bản– From-list: tên của các quan hệ.– Select-list: danh sách các thuộc tính của các quan hệ trong from-list– Qualification: Các phép so sánh • , =, ≤, ≥, , AND, OR, NOT.– DISTINCT: loại bỏ các giá trị trùng trong kết quả. 6 Câu truy vấn cơ bản• Conceptual Evaluation Strategy: – Semantics of an SQL query defined in terms of the following conceptual evaluation strategy: • Compute the cross-product of relation-list. • Discard resulting tuples if they fail qualifications. • Delete attributes that are not in target-list. • If DISTINCT is specified, eliminate duplicate rows. 7 Câu truy vấn cơ bản• A Note on Range Variables – Really needed only if the same relation appears twice in the FROM clause. SELECTS.sname FROMSailorsS,ReservesR WHERES.sid=R.sidANDbid=103 SELECTsname FROMSailors,Reserves WHERESailors.sid=Reserves.sidANDbid=103 8 Câu truy vấn cơ bản• Examples of Basic SQL Queries – Find the names and ages of all sailors. – Find the names and ages of all sailors 9 Câu truy vấn cơ bản– Find all sailors with a rating above 7.– When you want to retrieve all columns: 10 Câu truy vấn cơ bản– Find the sids of sailors who have reserved a red boat.– Find the names of sailors who have reserved a red boat. 11 Câu truy vấn cơ bản– Find the colors of boats reserved by Lubber– Find the names of sailors who have reserved at least one boat. 12 5.2 The Form of A Basic SQL Query• Expressions and Strings in the SELECT Command – Select-list: • Can be of the form expression AS column name, where expression is any arithmetic or string expression over column names and constants. • It can also contain aggregates such as sum and count. 13 Câu truy vấn cơ bản– Ex: Compute increments for the ratings of persons who have sailed two different boats on the same day 145.2 The Form of A Basic SQL Query– Find triples (of ages of sailors and two fields defined by expressions) for sailors whose names begin and end with B and contain at least three characters. SELECTS.age,age1=S.age5,2*S.ageASage2 FROMSailorsS WHERES.snameLIKE‘B_%B’ 15 Câu truy vấn cơ bản• String Comparisons – LIKE is used for string matching. – “_” stands for any one character and – “%”stands for 0 or more arbitrary characters Ex: Find the ages of sailors whose name begins and ends with B and has at least three characters. 16 Union, Intersect, And Except• UNION: – s1 UNION s2, result rows either in s1 or s2.• INTERSECT: – s1 INTERSECT s2, result rows in s1 and s2.• EXCEPT: – s1 EXCEPT s2, result rows in s1 but not in s2. (Some system recognize ‘MINUS’ for EXECPT)• IN, ANY, ALL, EXISTS to be covered in ‘Nested Queries’. 17Union, Intersect, And Except– Find the names of sailors who have reserved a red or a green boat 18Uni ...
Tìm kiếm theo từ khóa liên quan:
Cơ sở dữ liệu Hệ quản trị cơ sở dữ liệu Database Management System Ngôn ngữ SQL Câu truy vấn Structured Query LanguageTài liệu có liên quan:
-
62 trang 420 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 388 6 0 -
13 trang 342 0 0
-
Giáo trình Cơ sở dữ liệu: Phần 2 - TS. Nguyễn Hoàng Sơn
158 trang 318 0 0 -
Phân tích thiết kế hệ thống - Biểu đồ trạng thái
20 trang 315 0 0 -
Giáo án Tin học lớp 12 (Trọn bộ cả năm)
180 trang 307 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 296 1 0 -
Thực hiện truy vấn không gian với WebGIS
8 trang 280 0 0 -
Đề cương chi tiết học phần Quản trị cơ sở dữ liệu (Database Management Systems - DBMS)
14 trang 254 0 0 -
Giáo trình về dữ liệu và các mô hình cơ sở dữ liệu
62 trang 225 0 0