Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "(C) 2000, The University of Michigan 1 Database Application Design Handout #5 February 4, 2000."— Presentation transcript:

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

2 (C) 2000, The University of Michigan 2 Course information Instructor: Dragomir R. Radev (radev@si.umich.edu) Office: 305A, West Hall Phone: (734) 615-5225 Office hours: Thursdays 3-4 and Fridays 1-2 Course page: http://www.si.umich.edu/~radev/654w00 Class meets on Fridays, 2:30 - 5:30 PM, 311 WH

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

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

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

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

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

8 (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)

9 (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?

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

11 (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

12 (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

13 (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

14 (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

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

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

17 (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)

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

19 (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)

20 (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)

21 (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))

22 (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’)

23 (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!

24 (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

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

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

27 (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


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

Similar presentations


Ads by Google