ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: www.cse.yorku.ca/~gordon/itec3220S07 Office: CSEB3020.

Slides:



Advertisements
Similar presentations
ER Model For a college DB
Advertisements

Advanced SQL (part 1) CS263 Lecture 7.
© Abdou Illia MIS Spring 2014
© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Joins and Sub-queries in SQL.
ITEC 3220M Using and Designing Database Systems
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following:  List the capabilities of SQL SELECT statements.
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
1 SQL-Structured Query Language SQL is the most common language used for creating and querying relational databases. Many users can access a database applications.
Sample queries Practice in using Oracle SQL (1 of 2)
Concepts of Database Management, 4th Edition, Pratt & Adamski
Attribute databases. GIS Definition Diagram Output Query Results.
Entity PrimaryKey Attribute relationship Cardinality: zero to many Cardinality: one and only one Cardinality: one to many Explanation Entity Relationship.
©Silberschatz, Korth and Sudarshan3.1Database System Concepts - 6 th Edition SQL Schema Changes and table updates instructor teaches.
1 Chapter 4 Enhanced E-R Model. 2 Supertypes and Subtypes Subtype: A subgrouping of the entities in an entity type which has attributes that are distinct.
COURSE REGISTRATION SYSTEM Case study IST2101. Case Study: Course Registration (1) IST2102 You are helping Penn State create a course registration system.
Subqueries. So far when data has been filtered the filter has been known and simply added to the Where clause but often you don’t know what the filter.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Concepts of Database Management Seventh Edition
SQL – Part II Yong Choi School of Business CSU, Bakersfield.
Database System SQL November 1st, 2009 Software Park, Bangkok Thailand Pree Thiengburanathum College of Arts and Media Chiang Mai University.
Copyright, Harris Corporation & Ophir Frieder, Normal Forms “Why be normal?” - Author unknown Normal.
ITBIS373 Database Development
A Guide to MySQL 5. 2 Objectives Use joins to retrieve data from more than one table Use the IN and EXISTS operators to query multiple tables Use a subquery.
IST 210: ORGANIZATION OF DATA Chapter 1. Getting Started IST210 1.
Normalization Process: Exercise 1: Step 1 IST2101 Step 1. Identify all the candidate keys of the relation. StudentNumber.
Concepts of Database Management Seventh Edition
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 4 Multiple-Table Queries
CpSc 3220 The Language of SQL The Language of SQL Chapters
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 4: Intermediate.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
COMP231 Tutorial 1 ER Model and ER to Relational Schema.
Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query Sort.
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2. The Relational Model (cont.) IST2101. Review: Determinant vs. Candidate Key IST2102 DeterminantsCandidate Key (StudentID, CourseID) StudentID.
Exam 1 Review: ERDs, Schemas, SQL Out Describe Elements of an ERD Create Schema from ERD Notes: Associative Entities.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Assignment 1 Uploaded to course website Due next Tuesday, Sep 1, at 11:59pm.
Database Design I (In-Class Exercise Answer) IST 210: Organization of Data IST2101.
SQL SELECT Getting Data from the Database. Basic Format SELECT, FROM WHERE (=, >, LIKE, IN) ORDER BY ; SELECT LastName, FirstName, Phone, City FROM Customer.
A Guide to SQL, Eighth Edition Chapter Five Multiple-Table Queries.
Relational Database in Access Student System As always please use speaker notes!
The Student Registry Database Ian Van Houdt and Muna alfahad.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
SQL advanced select using Oracle 1 Multiple Tables: Joins and Set Operations Subqueries: Nested Queries.
Relational Databases. SQL Sub-queries: queries within queries  So far when data has been filtered the filter has been known and simply added to the Where.
Concepts of Database Management Seventh Edition Chapter 4 Keys and Relationship.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
Southern Methodist University CSE CSE 2337 Introduction to Data Management Chapter 2.
Chapter 1. Getting Started IST 210: Organization of Data IST2101.
DATA MODELING AND ENTITY-RELATIONSHIP MODEL II IST 210: Organization of Data IST210 1.
Problems 7/27/02. 3, p5 Student Course Student-Course Stu-ID Course-ID Grade.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
CS3220 Web and Internet Programming More SQL
Chapter 3 Introduction to SQL(3)
SQL in Oracle.
Using and Designing Database Systems
Chapter 5 STUDENT-COURSE
Chapter 4: Intermediate SQL Joins
CSC 453 Database Systems Lecture
Yong Choi School of Business CSU, Bakersfield
Chapter 2 Modeling Data in the Organization
ITEC 3220A Using and Designing Database Systems
ITEC 3220M Using and Designing Database Systems
A Very Brief Introduction to Relational Databases
Database 2.
Presentation transcript:

ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020

Chapter 8 Advanced Structured Query Language (SQL)

3 SQL Queries Single table query Multiple table query –Nesting query (subquery) Using IN Using EXISTS –Join Table

4 Examples SELECT Order_Num FROM ORDERS WHERE Order_Num IN (SELECT Order_Num FROM ORDER_LINE WHERE Part_Num =1234;

5 Examples (Cont’d) SELECT Order_Num FROM ORDERS WHERE EXISTS (SELECT * FROM ORDER_LINE WHERE ORDERS.Order_Num = ORDERLINE.Order_Num AND Part_Num =1234;

6 Examples (Cont’d) SELECT S.Last, S.First, C.Last, C.First FROM SALES_REP S, CUSTOMER C WHERE S.Srep_Num = C. Srep_Num

7 SQL Exercise Write SQL code that will create the relations shown. Assume the following attribute data types: –Student_ID: integer –Student_Name: 25 characters –Faculty_ID: integer –Faculty_Name: 25 characters –Course_ID: 25 characters –Course_Name: 15 characters –Date_Qualified: date –Section_ID: integer –Semester: 7 characters

8 SQL Exercise (Cont’d) STUDENT (Primary key: Student_ID) Student_ ID Student_ Name 38214Letersky 54907Altvater 66324Aiken 70542Marra IS_QUALIFIED (Primary key: Faculty_ID, Course_ID) Faculty_ ID Course_I D Date_ Qualified 2143ISM31129/ ISM42129/ ISM49309/ ISM31139/ ISM31129/1991

9 SQL Exercise (Cont’d) FACULTY (Primary key: Faculty_ID) Faculty_I D Faculty_Name 2143Birkin 3467Berndt 4756Collins SECTION (Primary key: Section_ID) Section_IDCourse_ID 2712ISM ISM ISM ISM4930

10 SQL Exercise (Cont’d) COURSE ((Primary key: Course_ID) Course_IDCourse_ Name ISM3113Syst Analysis ISM3112Syst Design ISM4212Database ISM4930Networking IS_REGISTERED (Primary key: Student_ID, Section_ID) Student_I D Section_I D Semester I I I I

11 SQL Exercise (Cont’d) Write SQL queries to answer the following questions: –Is any instructor qualified to teach ISM 3113 and not qualified to teach ISM 4930? –How many students are enrolled in section 2714 during semester I – 2001? –Display all the courses (Course_Name) for which Professor Berndt has been qualified. – Which students were not enrolled in any courses during semester I – 2001?

12 Exercise Write SQL codes to create the following tables Customer_ ID Customer_N ame CityState 1Value Furniture PlanoTX 2Home furnishings AlbanyNY 3Eastern Furniture CarteretNJ 4Furniture Gallery PlanoTX CUSTOMER Order_IDProduct_IDQuan ORDER_LINE

13 Exercise (Cont’d) Order_IDOrder_DateCustomer_ID Oct Oct Oct ORDER PRODUCT Product_IDDescriptionProduct_finishStandard_price 1End TableCherry175 2Coffee TableNatural Ash200 3Computer DeskNatural Ash375

14 Exercise (Cont’d) Use SQL to design the following queries: –How many different items were ordered on order number 1001? –List product ID and standard price for all desks and all tables that cost more than $200. –What furniture is not made of cherry?

15 Exercise (Cont’d) Use SQL to design the following queries: –List all the customers who live in FL, TX and CA. –Find only states with more than one customer. –What are order numbers that have included furniture finished in natural Ash. –What are the names of all customers who have placed orders?

16 Exercise (Cont’d) Use SQL to design the following queries: –For each customer who has placed an order, what is the customer’s name and order number? –Which customers have not placed any orders for computer desk? –List the product name and price with the highest standard price.