Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 157B: Database Management Systems II January 23 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.

Similar presentations


Presentation on theme: "CS 157B: Database Management Systems II January 23 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak."— Presentation transcript:

1 CS 157B: Database Management Systems II January 23 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak www.cs.sjsu.edu/~mak

2 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 2 CS 157B / SE 157B  Database Management Systems II A survey course A deep course Instructor: Ron Mak Class website: http://www.cs.sjsu.edu/~mak/http://www.cs.sjsu.edu/~mak/ Section 1: MW 3:00 – 4:15 PM in MH 222 Section 2: MW 6:00 – 7:15 PM in MH 222

3 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 3 CS 157B / SE 157B  Both sections are currently full. If you want to try get onto the class, pick up an Add Form from me, fill it out, and return it at the end of this class. I will put you on the waiting list of your desired section and send you an add code whenever an opening occurs. Graduating seniors have highest priority on the waiting list.

4 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 4 Rough Semester Outline WeekTopic 1-3Object-relational mapping (ORM) 4-5Extensible Markup Language (XML) 6-7Web services Midterm #1 (Wednesday, March 6) 8-9Data warehousing Spring recess 10-11Data warehousing, continued Midterm #2 (Monday, April 15) 12-14Data virtualization 15-16Content management Sec.Final exam 1Thurs, May 16 12:15-2:30 PM MH 222 2Wed, May 15 5:15-7:30 pm PM MH 222

5 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 5 Form Project Teams  3 students each. Pick a team name.  Each team member will get the same score for each team project.  Teams will last the entire semester. Choose your team members wisely!  Someone from each team send me: Your team name Name and email address of each team member _

6 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 6 Projects  One- or two-week projects Topics: ORM, XML, web services  Three- or four-week projects Topics: data warehousing, data virtualization  Each project involves: Research on the topic. A working application that uses the topic’s technology. A short report that describes the application, how it uses the technology, and how to run it.  Each project is worth a maximum of 100 points. Each team member gets the same score. Late projects lose 20 points plus an additional 20 points for each 24 hours after the due date.

7 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 7 Oral Presentations  Each team will have at least one opportunity during the semester to give an oral presentation in front of the class. Describe a project application. Do a demo. _

8 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 8 Postmortem Reports  At the end of the semester, each student will individually turn in a short (a few paragraphs) private individual postmortem report that includes: A brief description of what you learned in the course. An assessment of your accomplishments for your team on the projects. An assessment of each of your other project team members. _

9 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 9 Grading  Weights 65% projects* 10% midterm #1** 10% midterm #2** 15% final**  Each project and exam will be scored but not given a letter grade.  Final individual class letter grades will be based on the class curve. Adjustments up or down depending on the level and quality of your participation and by your team members’ assessments of your performance. *team scores **individual scores

10 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 10 Take roll

11 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 11 Data Independence  Goal: Loose coupling between applications and the data repository. Manage complexity. Manage change.  Applications should not need to know: Where the data is stored (location of the repository). How it is stored (file formats and organizations, etc.). Access mechanisms. _

12 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 12 Data Modeling  A data model is a diagram that shows what data an application works with and how the data is used. Model data that will be persisted (written to and read from a data repository).  For databases, objects are called entities. Model entities and their relationships to each other. _

13 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 13 Data Modeling  Conceptual data model A high-level user-oriented description of the data.  entities  relationships among the entities  who will use the data (access control)  how it will be used (use cases)  Logical data model A diagram showing names, attributes, keys, and relations.  Physical data model A configuration specification or a script to build the repository. Used by repository developers and maintainers.

14 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 14 Conceptual Data Model Example  Student, teacher, and class entities and their attributes. Student  id  name  contact information  which classes taken Teacher  id  name  contact information  which classes taught Class  class code  subject name  class room number

15 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 15 Conceptual Data Model Example  Sample queries What teachers does this student have? What classes does this teacher teach? Who is the teacher of this class? Which students are in this class? Which students are taught by this teacher?  These queries suggest there are binary relationships (associations) between entities!

16 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 16 The Relational Data Model  Data element: a value that is stored in the repository (i.e., the database). Values are typed. A value can be null.  Entity: a group of data elements that together are meaningful for a person or an application. Similar to objects. Each data element is the value of an attribute of the entity. _

17 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 17 The Relational Data Model  Table: a conceptual two-dimensional structure that contains entities of a particular type. Also called a relation. Each row (also called a record) contains the attribute values of one entity. Each column (also called a field) holds an attribute value. table  relation row  entity rows and columns  records and fields attribute value  data element

18 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 18 Logical Data Model  Initial version IdNameClass_codeSubjectRoom 7003Rogers, Tom926Java programming101 7008Thompson, Art908Data structures114 7012Lane, John951Software engineering210 7012Lane, John974Operating systems109 7051Flynn, Mabel931Compilers222 John Lane teaches two classes. Each table has a primary key (PK) field whose value in each record uniquely identifies that record. IdNameTeacher_id_1Teacher_id_2Teacher_id_3 1001Doe, John700370127008 1005Novak, Tim70127008null 1009Klein, Leslienull 1014Jane, Mary7051null 1021Smith, Kim700370127051 Student Teacher  Student id name which teachers  Teacher id name which classes taught  Class class code subject name class room number PK

19 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 19 Normalization  Relational tables need to be normalized. Improve the stability of the model.  More resilient to change. Faster record insertions and updates. Improve data quality.  There are six normal forms, but we will only consider the first two. Each normal form includes the lower normal forms.  Example: A database in second normal form is also in first normal form.

20 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 20 First Normal Form (1NF)  Separate multi-valued data elements. Break the name fields into last name and first name fields. IdLastFirstTeacher_id_1Teacher_id_2Teacher_id_3 1001DoeJohn700370127008 1005NovakTim70127008null 1009KleinLeslienull 1014JaneMary7051null 1021SmithKim700370127051 IdLastFirstClass_codeSubjectRoom 7003RogersTom926Java programming101 7008ThompsonArt908Data structures114 7012LaneJohn951Software engineering210 7012LaneJohn974Operating systems109 7051FlynnMabel931Compilers222 Student Teacher IdNameTeacher_id_1Teacher_id_2Teacher_id_3 1001Doe, John700370127008 1005Novak, Tim70127008null 1009Klein, Leslienull 1014Jane, Mary7051null 1021Smith, Kim700370127051 IdNameClass_codeSubjectRoom 7003Rogers, Tom926Java programming101 7008Thompson, Art908Data structures114 7012Lane, John951Software engineering210 7012Lane, John974Operating systems109 7051Flynn, Mabel931Compilers222

21 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 21 First Normal Form  Move repeating data elements to a new table. IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim Student_idTeacher_id 10017003 10017012 10017008 10057012 10057008 10147051 10217003 10217012 10217051 Join table IdLastFirstClass_codeSubjectRoom 7003RogersTom926Java programming101 7008ThompsonArt908Data structures114 7012LaneJohn951Software engineering210 7012LaneJohn974Operating systems109 7051FlynnMabel931Compilers222 Student Teacher Student_Teacher IdLastFirstTeacher_id_1Teacher_id_2Teacher_id_3 1001DoeJohn700370127008 1005NovakTim70127008null 1009KleinLeslienull 1014JaneMary7051null 1021SmithKim700370127051

22 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 22 Problem!  Suppose Prof. Lane decides he doesn’t want to teach Operating Systems anymore and we delete that row.  What other information do we lose as a result? We lose the fact that the class is taught in Room 109.  The problem arises because the Teacher table really contains two separate sets of data: teacher data and class data. IdLastFirstClass_codeSubjectRoom 7003RogersTom926Java programming101 7008ThompsonArt908Data structures114 7012LaneJohn951Software engineering210 7012LaneJohn974Operating systems109 7051FlynnMabel931Compilers222 Teacher

23 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 23 Second Normal Form  Keep related data together (cohesiveness). IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel Class_codeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 TeacherClass Primary key (PK) Foreign key (FK) IdLastFirstClass_codeSubjectRoom 7003RogersTom926Java programming101 7008ThompsonArt908Data structures114 7012LaneJohn951Software engineering210 7012LaneJohn974Operating systems109 7051FlynnMabel931Compilers222 Teacher

24 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 24 Final Database Structure IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 Student_idClass_code 1001926 1001951 1001908 1005974 1005908 1014931 1021926 1021974 1021931 IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel Teacher Student Class Student_Class  John Doe takes Java programming, software engineering, and data structures.  The Java Programming class has John Doe and Kim Smith.  Mabel Flynn teaches compilers.

25 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 25 Entity-Relationship (ER) Diagrams  Entity-Relationship (ER) diagrams are logical data modeling diagrams. Very similar in concept to UML diagrams. There are several styles of ER diagrams.  We’ll use crow’s feet diagrams.  We’ll use a tool to generate these diagrams. _

26 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 26 One-to-One Relationship  One (each) teacher has one contact information. IdLastFirstContact_id 7003RogersTom207 7008ThompsonArt190 7012LaneJohn458 7051FlynnMabel856 IdEmail_address 458jlane@sjsu.edu 856mflynn@sjsu.edu 207trogers@sjsu.edu 190athompson@sjsu.edu TeacherContact_Info one

27 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 27 One-to-Many Relationship  One (each) teacher teaches 0, 1, or many classes. IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 TeacherClass onezeroonemany Database cardinality is only 0, 1, or many (more than 1).

28 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 28 Many-to-Many Relationship IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 Student_idClass_code 1001926 1001951 1001908 1005974 1005908 1014931 1021926 1021974 1021931 Student Class Student_Class  A student has 0, 1 or many classes.  A class has 1 or many students. Class Student Student-Class

29 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 29 Complete Entity Diagram code (PK) teacher_id (FK) subject room Class CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 Class

30 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 30 SQL  Structured Query Language (SQL) An industry standard But has many proprietary extensions  Language for managing data in a relational database. Create and drop (delete) databases Create, alter, and drop tables of a database Retrieve, insert, update, and delete data in the tables. _

31 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 31 SQL Query Examples  What is the class code of the Java programming class? CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 Class SELECT code FROM class WHERE subject = 'Java programming' +------+ | code | +------+ | 926 | +------+ Source tablesDesired attributes Selection criteria

32 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 32 SQL Query Examples  Who teaches Java programming? IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 ClassTeacher SELECT first, last FROM teacher, class WHERE id = teacher_id AND subject = 'Java programming' +-------+--------+ | first | last | +-------+--------+ | Tom | Rogers | +-------+--------+ Selecting from multiple tables is called a join.

33 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 33 SQL Query Examples  What classes does John Lane teach? SELECT code, subject FROM teacher, class WHERE last = 'Lane' AND first = 'John' AND id = teacher_id +------+----------------------+ | code | subject | +------+----------------------+ | 951 | Software engineering | | 974 | Operating systems | +------+----------------------+ IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 ClassTeacher

34 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 34 SQL Query Examples  Who takes Java programming? IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 Student_idClass_code 1001926 1001951 1001908 1005974 1005908 1014931 1021926 1021974 1021931 SELECT id, last, first FROM student, class, student_class WHERE subject = 'Java programming' AND code = class_code AND id = student_id +------+-------+-------+ | id | last | first | +------+-------+-------+ | 1001 | Doe | John | | 1021 | Smith | Kim | +------+-------+-------+ Class Student_Class Student

35 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 35 SQL Query Examples  What classes does John Doe take? IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 Student_idClass_code 1001926 1001951 1001908 1005974 1005908 1014931 1021926 1021974 1021931 SELECT code, subject FROM student, class, student_class WHERE last = 'Doe' AND first = 'John' AND id = student_id AND code = class_code +------+----------------------+ | code | subject | +------+----------------------+ | 908 | Data structures | | 926 | Java programming | | 951 | Software engineering | +------+----------------------+ ClassStudent Student_Class

36 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 36 SQL Query Examples  Who are John Lane’s students? IdLastFirst 1001DoeJohn 1005NovakTim 1009KleinLeslie 1014JaneMary 1021SmithKim CodeTeacher_idSubjectRoom 9087008Data structures114 9267003Java programming101 9317051Compilers222 9517012Software engineering210 9747012Operating systems109 Student_idClass_code 1001926 1001951 1001908 1005974 1005908 1014931 1021926 1021974 1021931 SELECT student.first, student.last, subject FROM student, teacher, class, student_class WHERE teacher.last = 'Lane' AND teacher.first = 'John' AND teacher_id = teacher.id AND code = class_code AND student.id = student_id ORDER BY subject, student.last +-------+-------+----------------------+ | first | last | subject | +-------+-------+----------------------+ | Tim | Novak | Operating systems | | Kim | Smith | Operating systems | | John | Doe | Software engineering | +-------+-------+----------------------+ IdLastFirst 7003RogersTom 7008ThompsonArt 7012LaneJohn 7051FlynnMabel Teacher StudentClass Student_Class

37 Department of Computer Science Spring 2013: January 23 CS 157B: Database Management Systems II © R. Mak 37 MySQL  Popular open-source relational database management system (RDBMS). The M in LAMP (Linux+Apache+MySQL+PHP)  or Perl or Python Now part of Oracle. Download from http://www.mysql.org/http://www.mysql.org/


Download ppt "CS 157B: Database Management Systems II January 23 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak."

Similar presentations


Ads by Google