Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See www.db-book.com for conditions on re-usewww.db-book.com 3 SQL.

Slides:



Advertisements
Similar presentations
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
Advertisements

Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Appendix B: Advanced.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
E-R Diagram for a Banking Enterprise
Chapter 2 Relational Model (part II) Hankz Hankui Zhuo
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Extended.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Ordering the Display of Tuples List in alphabetic order the names of all customers having.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Outer Join Aggregate Functions.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
SQL Neyha Amar CS 157A, Fall Inserting The insert statement is used to add a row of data into a table Strings should be enclosed in single quotes,
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
MySQL Tutorial (2) Introduction to Database. Banking Example branch (branch-name, branch-city, assets) customer (customer-name, customer-street, customer-city)
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 5: Other Relational.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Calculus Objectives  Tuple Calculus  Domain Calculus  QBE & SQL  Related Examples.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Dr. Alexandra I. Cristea.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Hashing.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Chapter 4: SQL Basic Structure Set Operations Aggregate Functions Null Values Nested Subqueries.
©Silberschatz, Korth and Sudarshan4.1Database System Concepts Null Values It is possible for tuples to have a null value for some of their attributes The.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Outer Join n An extension of the join operation that avoids loss.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 7: Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Computing & Information Sciences Kansas State University Monday, 08 Sep 2008CIS 560: Database System Concepts Lecture 5 of 42 Monday, 08 September 2008.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Relational Model.
©Silberschatz, Korth and Sudarshan5.1Database System Concepts Chapter 5: Other Relational Query Languages Tuple Relational Calculus Domain Relational Calculus.
ICOM 5016 – Introduction to Database Systems Lecture 8 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Example.
2.1 Chapter 2: Relational Model. 2.2 Chapter 2: Relational Model Structure of Relational Databases Fundamental Relational-Algebra-Operations Additional.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Indexing.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Introduction.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Appendix B: Advanced.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Extended Relational-Algebra-Operations Generalized Projection Aggregate Functions Outer Join.
©Silberschatz, Korth and Sudarshan1Database System Concepts The Relational Model Structure of Relational Databases Relational Algebra.
MySQL Tutorial Introduction to Database. Introduction of MySQL  MySQL is an SQL (Structured Query Language) based relational database management system.
ICOM 5016 – Introduction to Database Systems Lecture 6 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 7: Entity-Relationship.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL Bambang.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts Chapter 3: Relational Model Structure of Relational Databases Relational Algebra Tuple Relational.
Database System Concepts ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: SQL.
Database System Concepts, 5 th Ed. ©Silberschatz, Korth and Sudarshan Chapter 2: Relational Model.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 6: Formal Relational.
Structured Query Language
Presentation transcript:

Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com 3 SQL

©Silberschatz, Korth and Sudarshan3.2Database System Concepts, 5 th Edition, Oct 5, a. Select count(*) from license a Where exists(select 1 from owns b,person c where a.car=b.license and b.driver_id=c.drive_id and c.name=‘John Smith’) b. Update license set damage_amount=3000 where report_number=‘AR2197’ and car=‘AABB2000’

©Silberschatz, Korth and Sudarshan3.3Database System Concepts, 5 th Edition, Oct 5, a. select employee_name from works where company_name=‘First Bank Corporation’ b. select a.employee_name,b.employee_name from employee a,employee b where a.city=b.city and exists( select 1 from works c,works d, company e,company f where a.employee_name=c.employee_name and b.employee_name=d.employee_name and c.company_name=e.company_name and d.company_name=f.company_name and e.city=f.city)

©Silberschatz, Korth and Sudarshan3.4Database System Concepts, 5 th Edition, Oct 5, c. select a.employee_name,b.employee_name from employee a,employee b where a.city=b.city and a.street=b.street and exists( select 1 from mamages c,manages d where a.employee_name=c.employee_name and b.employee_name=d.employee_name and c.manager_name=d.manager_name) d. select employee_name from works a where a.salary > (select avg(b.salary) from works b where a.company_name=b.company_name group by b.company_name ) e. select company_name from works group by company_name having sum(salary) <= all (select sum(salary) from works group by company_name)

©Silberschatz, Korth and Sudarshan3.5Database System Concepts, 5 th Edition, Oct 5, e. select company_name from (select company_name,sum(salary),rownum from works group by company_name order by sum(salary)) where rownum=1; select company_name from (select company_name,rank() over order by sum(salary) rank from works group by company_name ) where rank=1;

©Silberschatz, Korth and Sudarshan3.6Database System Concepts, 5 th Edition, Oct 5, a. update works set salary=salary*1.1 where company_name=‘First Bank Corporation’ b. update works a set salary=salary*1.1 where company_name=‘First Bank Corporation’ and exists(select 1 from manages b where a.employee_name=b.manager_name) c. delete works where company_name=‘Small Bank Corporation’

©Silberschatz, Korth and Sudarshan3.7Database System Concepts, 5 th Edition, Oct 5, select A from R select * from R where B=17 select * from R,S select A,F from R,S where C=D

©Silberschatz, Korth and Sudarshan3.8Database System Concepts, 5 th Edition, Oct 5, select * from r1 union select * from r2 select * from r1 intersect select * from r2 select * from r1 minus select * from r2

©Silberschatz, Korth and Sudarshan3.9Database System Concepts, 5 th Edition, Oct 5, create view man_emp_avg_salary(manager_name,avg_salary) as select a.manager_name,avg(b.salary) from works a,manages b where a.empolyee_name=b.empolyee_name and b.empolyee_name<>b.manager_name group by a.mamager_name

©Silberschatz, Korth and Sudarshan3.10Database System Concepts, 5 th Edition, Oct 5, select branch_name from (select branch_name,sum(balance) summary from account group by branch_name) a where a.summary >(select avg(summary) from (select branch_name,sum(balance) summary from account group by branch_name) ) select branch_name from account group by branch_name having sum(balance) >(select avg(summary) from (select branch_name,sum(balance) summary from account group by branch_name) )

©Silberschatz, Korth and Sudarshan3.11Database System Concepts, 5 th Edition, Oct 5, create view account_Deer_Park (account_number,customer_name) as select account_number,customer_name from account a,customer b,depositor c where a.account_number=d.account_number and c.customer_name=b.customer_name and a.branch_name=‘Deer Park’ create view customer_no_loan (customer_name,customer_street,customer_city) as select customer_name,customer_street,customer_city from customer a where exists(select 1 from depositor b where a.customer_name=b.customer_name) and not exists(select 1 from borrower c where a.customer_name=c.customer_name)

©Silberschatz, Korth and Sudarshan3.12Database System Concepts, 5 th Edition, Oct 5, create view customer_Rock_Ridge(customer_name,avg_balance) as select c.customer_name,avg(a.balance) from account a,depositor b,customer c where a.account_number=b.account_number and b.customer_name=c.customer_name group by c.customer_name where a.branch_name=‘Rock_Ridge’

©Silberschatz, Korth and Sudarshan3.13Database System Concepts, 5 th Edition, Oct 5, select name from employee a where exists(select 1 from loan b,books c where a.empno=b.empno and b.isbn=c.isbn and c.publisher=‘McGraw-Hill’) select name from employee a where not exists(select 1 from books c where c.publisher=‘McGraw- Hill’ and not exists(select 1 from loan b where a.empno=b.empno and b.isbn=c.isbn ) select x.name,y.publisher from employee x, (select empno,publisher from books b,loan c where and b.isbn=c.isbn group by empno,publisher having count(*)>5) y where x.empno=y.empno

©Silberschatz, Korth and Sudarshan3.14Database System Concepts, 5 th Edition, Oct 5, select student_id,student_name,nvl(count(course_id),0) from student a left outer join registered b on a.student_id=b.student_id group by student_id,student_name select student_id,student_name,(count(course_id) from student a,registered b where a.student_id=b.student_id group by student_id,student_name union all select student_id,student_name,0 from student a where not exists(select 1 from registered b where a.student_id=b.student_id)

©Silberschatz, Korth and Sudarshan3.15Database System Concepts, 5 th Edition, Oct 5, select student_id,dense_rank() over (order by score desc) from marks