(C) 2000, The University of Michigan 1 Database Application Design Handout #5 February 4, 2000.

Slides:



Advertisements
Similar presentations
Structured Query Language b Querying a Single Table b Querying Multiple Tables b EXISTS and NOT EXISTS b Changing Data.
Advertisements

TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos & A. Pavlo Lecture#6: Rel. model - SQL part1 (R&G, chapter.
Information Resources Management February 27, 2001.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 8 Foundations of Relational Implementation.
© 2002 by Prentice Hall 1 SI 654 Database Application Design Winter 2004 Dragomir R. Radev.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
1 Query Languages: How to build or interrogate a relational database Structured Query Language (SQL)
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 2-1 David M. Kroenke’s Chapter Two: Introduction to Structured Query.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 8 Foundations of Relational Implementation.
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
1/2/20101 Lecture 4 on Structural Query Language To study Structural Query Language (SQL) as a non-procedural computer language to access relational database.
Structured Query Language Chapter Three DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
© 2002 by Prentice Hall 1 SI 654 Database Application Design Winter 2003 Dragomir R. Radev.
Microsoft Access 2010 Chapter 7 Using SQL.
1 Announcements Read 6.7 – 6.10 for Friday Homework 6, due Friday 10/29 Research paper –List of sources - due 10/29 Department Seminar –The Role of Experimentation.
Structured Query Language
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos Rel. model - SQL part1.
(C) 2000, The University of Michigan 1 Database Application Design Handout #3 January 21, 2000.
1 IT420: Database Management and Organization SQL - Data Manipulation Language 27 January 2006 Adina Crăiniceanu
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
(C) 2000, The University of Michigan 1 Database Application Design Handout #4 January 28, 2000.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
(C) 2000, The University of Michigan 1 Database Application Design Handout #10 March 17, 2000.
Instructor: Jinze Liu Fall Basic Components (2) Relational Database Web-Interface Done before mid-term Must-Have Components (2) Security: access.
(C) 2000, The University of Michigan 1 Database Application Design Handout #8 February 25, 2000.
Using Special Operators (LIKE and IN)
(C) 2000, The University of Michigan 1 Database Application Design Handout #7 February 18, 2000.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
Chapter 8 Foundations of Relational Implementation David M. Kroenke Database Processing © 2000 Prentice Hall.
Relational Algebra CS420. Relation A relation is a two dimensional table that Rows contain data about an entity Columns contains data about attributes.
Chapter 9 Structured Query Language David M. Kroenke Database Processing © 2000 Prentice Hall.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
SQL “Structured Query Language; standard language for relational data manipulation” DB2, SQL/DS, Oracle, INGRES, SYBASE, SQL Server, dBase/Win, Paradox,
SQL SeQueL -Structured Query Language SQL SQL better support for Algebraic operations SQL Post-Relational row and column types,
Chapter 8 Database Redesign We only discuss complex sub-queries.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
1 IT420: Database Management and Organization SQL part 3 7 February 2006 Adina Crăiniceanu
Querying Database ISYS 363.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
Structured Query Language
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
CS 405G: Introduction to Database Systems Instructor: Jinze Liu.
(C) 2003, The University of Michigan1 Information Retrieval Handout #10 April 7, 2003.
CS 3630 Database Design and Implementation. Base Table and View Base Table Stored on disk View Virtual table Records are not stored on disk Query is stored.
1 SQL Chapter 9 – 8 th edition With help from Chapter 2 – 10 th edition.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Structured Query Language
CH 9 SQL 9.1 Querying A Single Table 9.2 Querying Multiple Tables
Ch 8: Foundations of Relational Implementation
PL/SQL LANGUAGE MULITPLE CHOICE QUESTION SET-1
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Querying Database ISYS 363.
Chapter 4 Summary Query.
Database systems Lecture 3 – SQL + CRUD
Agenda SQL Queries Join. MGS 4020 Business Intelligence Relational Algebra and Structured Query Language Jul 3, 2018.
SQL: Structured Query Language
Presentation transcript:

(C) 2000, The University of Michigan 1 Database Application Design Handout #5 February 4, 2000

(C) 2000, The University of Michigan 2 Course information Instructor: Dragomir R. Radev Office: 305A, West Hall Phone: (734) Office hours: Thursdays 3-4 and Fridays 1-2 Course page: Class meets on Fridays, 2:30 - 5:30 PM, 311 WH

(C) 2000, The University of Michigan 3 Foundations of relational implementation (cont’d)

(C) 2000, The University of Michigan 4 Expressing queries in relational algebra

(C) 2000, The University of Michigan 5 Examples STUDENT

(C) 2000, The University of Michigan 6 Examples (Cont’d) ENROLLMENT

(C) 2000, The University of Michigan 7 Examples (Cont’d) CLASS

(C) 2000, The University of Michigan 8 Examples (Cont’d) Full set of relations: JUNIOR (Snum, Name, Major) HONOR-STUDENT (Number, Name, Interest) STUDENT (SID, Name, Major, GradeLevel, Age) CLASS (Name, Time, Room) ENROLLMENT (StudentNumber, ClassName, PositionNumber) FACULTY (FID, Name, Department)

(C) 2000, The University of Michigan 9 Examples (Cont’d) What are the names of all students? What are the student numbers of all students enrolled in a class? What are the student numbers of all students not enrolled in a class? What are the numbers of students enrolled in the class ‘BD445’? What are the names of the students enrolled in class ‘BD445’? What are the names and meeting times of ‘PARKS’ classes? Wwhat are the grade levels and meeting rooms of all students, including students not enrolled in a class?

(C) 2000, The University of Michigan 10 Structured Query Language (SQL)

(C) 2000, The University of Michigan 11 SQL Overview ANSI Standard Multitude of implementations SQL92 (ANSI) Not a programming language! Two major modes of use: embedded and interactive

(C) 2000, The University of Michigan 12 Projections in SQL SELECT SID, Name, Major FROM STUDENT SELECT Major FROM STUDENT SELECT DISTINCT Major FROM STUDENT

(C) 2000, The University of Michigan 13 Selections in SQL SELECT SID, Name, Major, GradeLevel, Age FROM STUDENT WHERE Major =‘MATH’ SELECT * FROM STUDENT WHERE Major =‘MATH’ SELECT * FROM STUDENT WHERE Major =‘MATH’ AND Age > 21

(C) 2000, The University of Michigan 14 Selections in SQL (Cont’d) Set values for the condition (IN, NOT IN) Ranges (BETWEEN) LIKE Wild cards (%, _) IS NULL

(C) 2000, The University of Michigan 15 Sorting in SQL ORDER BY ASC, DESC

(C) 2000, The University of Michigan 16 Built-in functions COUNT, SUM, AVG, MAX, MIN SELECT COUNT(*) FROM STUDENT SELECT COUNT(Major) FROM STUDENT

(C) 2000, The University of Michigan 17 Grouping GROUP BY HAVING Example: SELECT Major, COUNT(*) FROM STUDENT GROUP BY Major HAVING COUNT(*) > 2 Ordering (WHERE is computed first)

(C) 2000, The University of Michigan 18 Subqueries SELECT Name FROM STUDENT WHERE SID IN (SELECT StudentNumber FROM ENROLLMENT WHERE ClassName = ‘BD445’)

(C) 2000, The University of Michigan 19 Joins in SQL Using more than one table in a SELECT Comparing subqueries and joins –not equivalent Outer joins (ANSI vs. Access)

(C) 2000, The University of Michigan 20 EXISTS and NOT EXISTS SELECT DISTINCT StudentNumber FROM ENROLLMENT A WHERE EXISTS (SELECT * FROM ENROLLMENT B WHERE A.StudentNumber = B.StudentNumber AND A.ClassName NOT = B.ClassName)

(C) 2000, The University of Michigan 21 EXISTS and NOT EXISTS (Cont’d) SELECT Student.Name FROM STUDENT WHERE NOT EXISTS (SELECT * FROM ENROLLMENT WHERE NOT EXISTS (SELECT * FROM CLASS WHERE CLASS.Name = ENROLLMENT.ClassName AND ENROLLMENT.StudentNumber = STUDENT.SID))

(C) 2000, The University of Michigan 22 Inserting data INSERT INTO ENROLLMENT VALUES (400,’BD445’,44) INSERT INTO ENROLLMENT (StudentNumber,ClassName) VALUES (400,’BD445) INSERT INTO JUNIOR VALUES (SELECT SID, Name, Major FROM STUDENT WHERE GradeLevel = ‘JR’)

(C) 2000, The University of Michigan 23 Deleting data DELETE STUDENT WHERE STUDENT.SID = 100 DELETE ENROLLMENT WHERE ENROLLMENT.StudentNumber IN (SELECT STUDENT.SID FROM STUDENT WHERE STUDENT.Major = ‘Accounting’) DELETE STUDENT WHERE Student.Major = ‘Accounting’ Ordering!

(C) 2000, The University of Michigan 24 Updating data UPDATE ENROLLMENT SET PositionNumber = 44 WHERE SID = 400 UPDATE ENROLLMENT SET PositionNumber = MAX (PositionNumber) + 1 WHERE SID = 400

(C) 2000, The University of Michigan 25 Database design using E-R Models

(C) 2000, The University of Michigan 26 E-R Design Transforming user requirements represented using E-R models into relational database designs

(C) 2000, The University of Michigan 27 Readings for next time Kroenke –Chapter 10: Database application design YRK (optional) –Chapter 8: Database application architectures –Chapter 9: CGI programming