Download CS 160: Software Engineering - Department of Computer Science

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CS 185C/286: The History of Computing
October 31 Class Meeting
Department of Computer Science
San Jose State University
Fall 2011
Instructor: Ron Mak
www.cs.sjsu.edu/~mak
Don Chamberlin

History of Computing Speaker
Wednesday, Nov. 2, 6:00-7:00 PM
Auditorium ENGR 189


Reception before the talk in
ENGR 294 at 5:00 PM
“Fifty Years of Data:
How Advances in
Database Management
Have Helped to Shape
Our World”

Co-inventor of the SQL and
XQuery database languages
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
2
What is a Database?

A collection of information that lasts
over a long period of time


Can be accessed simultaneously by multiple
instances of an application or by instances of many
applications
Managed by a database management system
(DBMS)
_
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
3
Database Management System (DBMS)

Users can create new databases






Users can query (ask questions about) the data
Users can modify the data
Store large amounts (terabytes) of data
Store data for a long time (many years)
Ensure reliability


Specify the structure of the data (schema)
Recover from errors and failures
Ensure data integrity

Maintain proper relationships among data
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
4
DBMS, cont’d


Control access to data
by multiple users and applications
Ensure data operations are completed
(atomicity)


roll back partially completed operations
Maintain a data model, which determines:



structure of the data
operations on the data
constraints on the data
Department of Computer Science
Fall 2011: October 31
Types of data models
- hierarchical
- relational
- object-oriented
- object-relational
CS 185C/286: History of Computing
© R. Mak
5
The Relational Data Model

Data element: a value that is stored in 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

Each data element is the value of an attribute
of the entity
_
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
6
The Relational Data Model, cont’d

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
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
7
Logical Data Model

Initial version
Student
Each table has a primary key (PK) field whose value
in each record uniquely identifies that record.
Id
Name
Teacher_id_1
Teacher_id_2
Teacher_id_3
1001
Doe, John
7003
7012
7008

1005
Novak, Tim
7012
7008
null

1009
Klein, Leslie
null
null
null
1014
Jane, Mary
7051
null
null
1021
Smith, Kim
7003
7012
7051

Student


Teacher



PK
Teacher

Name
Class_code
Subject
Room

7003
Rogers, Tom
926
Java programming
101

7008
Thompson, Art
908
Data structures
114
7012
Lane, John
951
Software engineering
210
7012
Lane, John
974
Operating systems
109
7051
Flynn, Mabel
931
Compilers
222
CS 185C/286: History of Computing
© R. Mak
id
name
which classes
taught
Class
Id
PK
Department of Computer Science
Fall 2011: October 31
id
name
which teachers

class code
subject name
class room number
John Lane teaches
two classes.
8
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.
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
9
First Normal Form (1NF)

Separate multi-valued data elements.

Break the name fields into last name and first name fields.
Student
Teacher
Id
Name
Last
First
Teacher_id_1
Teacher_id_1
Teacher_id_2
Teacher_id_2
Teacher_id_3
Teacher_id_3
1001
Doe,
DoeJohn
7003
John
7003
7012 7012
7008 7008
1005
Novak,
NovakTim
7012
Tim
7012
7008 7008
null
null
1009
Klein,
KleinLeslie
null
Leslie
null
null
null
null
null
1014
Jane,
JaneMary
7051
Mary
7051
null
null
null
null
1021
Smith,
SmithKim
7003
Kim
7003
7012 7012
7051 7051
Id
Last
Name
7003
Rogers
Rogers, TomTom
926 926
Java programming
Java programming 101 101
7008
Thompson
Thompson, Art
Art
908 908
Data structures
Data structures
7012
Lane
Lane, John John 951 951
Software
Software
engineering
engineering210 210
7012
Lane
Lane, John John 974 974
Operating
Operating
systems
systems 109 109
7051
Flynn
Flynn, MabelMabel 931 931
Compilers
Compilers
Department of Computer Science
Fall 2011: October 31
First Class_code
Class_codeSubject
Subject
CS 185C/286: History of Computing
© R. Mak
RoomRoom
114 114
222 222
10
First Normal Form, cont’d

Student_Teacher
Move repeating data elements
to a new table.
Student
Student_id
Teacher_id
1001
7003
1001
7012
Id
Id
Last
Last
First
First
Teacher_id_1
Teacher_id_2
1001
7008
Teacher_id_3
1001
1001
Doe
Doe
John
John
7003
7012
1005
7008
7012
1005
1005
Novak
Novak
TimTim
7012
7008
1005
null
7008
1009
1009
Klein
Klein
Leslie
Leslie
null
null
1014
null
7051
1014
1014
Jane
Jane
Mary
Mary
7051
null
1021
null
7003
1021
1021
Smith
Smith
Kim
Kim
7003
7012
1021
7051
7012
1021
7051
Linking
table
Teacher
Id
Last
First
Class_code
Subject
Room
7003
Rogers
Tom
926
Java programming
101
7008
Thompson
Art
908
Data structures
114
7012
Lane
John
951
Software engineering
210
7012
Lane
John
974
Operating systems
109
7051
Flynn
Mabel
931
Compilers
222
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
11
Problem!
Teacher


Last
First
Class_code
Subject
Room
7003
Rogers
Tom
926
Java programming
101
7008
Thompson
Art
908
Data structures
114
7012
Lane
John
951
Software engineering
210
7012
Lane
John
974
Operating systems
109
7051
Flynn
Mabel
931
Compilers
222
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?


Id
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
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
12
Second Normal Form

Keep related data together (cohesiveness).
Teacher
Class
Id
Last
First
Class_code
Teacher_id
Subject
Room
7003
Rogers
Tom
908
7008
Data structures
114
7008
Thompson
Art
926
7003
Java programming
101
7012
Lane
John
931
7051
Compilers
222
7051
Flynn
Mabel
951
7012
Software engineering
210
974
7012
Operating systems
109
Primary key (PK)
Primary key (PK)
Department of Computer Science
Fall 2011: October 31
Foreign key (FK)
CS 185C/286: History of Computing
© R. Mak
13
Final Database Structure



John Doe takes Java programming, software
engineering, and data structures.
The Java Programming class has John Doe
and Kim Smith.
Mabel Flynn teaches compilers.
Student_Class
Student
Id
Last
First
1001
Doe
John
1005
Novak
Tim
1009
Klein
Leslie
1014
Jane
Mary
1021
Smith
Kim
Teacher
Student_id
Class_code
1001
926
1001
951
1001
908
1005
974
1005
908
1014
931
1021
926
1021
974
1021
931
Class
Code
Teacher_id
Subject
Room
Id
Last
First
908
7008
Data structures
114
7003
Rogers
Tom
926
7003
Java programming
101
7008
Thompson
Art
931
7051
Compilers
222
7012
Lane
John
951
7012
Software engineering
210
7051
Flynn
Mabel
974
7012
Operating systems
109
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
14
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.
_
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
15
SQL Query Examples

What is the class code of the Java programming class?
Class
Desired fields
Source tables
Code
Teacher_id
Subject
Room
908
7008
Data structures
114
926
7003
Java programming
101
931
7051
Compilers
222
951
7012
Software engineering
210
974
7012
Operating systems
109
SELECT code
FROM class
WHERE subject = 'Java programming'
Query
+------+
| code |
+------+
| 926 |
+------+
Results
Selection criteria
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
16
SQL Query Examples, cont’d

Who is teaching Java programming?
Teacher
Class
Id
Last
First
Code
Teacher_id
Subject
Room
7003
Rogers
Tom
908
7008
Data structures
114
7008
Thompson
Art
926
7003
Java programming
101
7012
Lane
John
931
7051
Compilers
222
7051
Flynn
Mabel
951
7012
Software engineering
210
974
7012
Operating systems
109
SELECT first, last
FROM teacher, class
WHERE id = teacher_id
AND subject = 'Java programming'
+-------+--------+
| first | last
|
+-------+--------+
| Tom
| Rogers |
+-------+--------+
Department of Computer Science
Fall 2011: October 31
Selecting from multiple tables
is called a join.
CS 185C/286: History of Computing
© R. Mak
17
SQL Query Examples, cont’d

What classes does John Lane teach?
Teacher
Class
Id
Last
First
Code
Teacher_id
Subject
Room
7003
Rogers
Tom
908
7008
Data structures
114
7008
Thompson
Art
926
7003
Java programming
101
7012
Lane
John
931
7051
Compilers
222
7051
Flynn
Mabel
951
7012
Software engineering
210
974
7012
Operating systems
109
SELECT code, subject
FROM teacher, class
WHERE last = 'Lane' AND first = 'John'
AND id = teacher_id
+------+----------------------+
| code | subject
|
+------+----------------------+
| 951 | Software engineering |
| 974 | Operating systems
|
+------+----------------------+
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
18
SQL Query Examples, cont’d

Who is taking Java programming?
Student_Class
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_id
Class_code
1001
926
1001
951
1001
908
1005
974
1005
908
1014
931
1021
926
1021
974
1021
931
Student
Code
Teacher_id
Subject
Room
Id
Last
First
908
7008
Data structures
114
1001
Doe
John
926
7003
Java programming
101
1005
Novak
Tim
931
7051
Compilers
222
1009
Klein
Leslie
951
7012
Software engineering
210
1014
Jane
Mary
974
7012
Operating systems
109
1021
Smith
Kim
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
19
SQL Query Examples, cont’d
Who are John Lane’s students and in which subjects?

Student_Class
Teacher
Class
Student_id
Class_code
1001
926
1001
951
1001
908
1005
974
1005
908
1014
931
1021
926
1021
974
1021
931
Student
Id
Last
First
Code
Teacher_id
Subject
Room
Id
Last
First
7003
Rogers
Tom
908
7008
Data structures
114
1001
Doe
John
7008
Thompson
Art
926
7003
Java programming
101
1005
Novak
Tim
7012
Lane
John
931
7051
Compilers
222
1009
Klein
Leslie
7051
Flynn
Mabel
951
7012
Software engineering
210
1014
Jane
Mary
974
7012
Operating systems
109
1021
Smith
Kim
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
20
SQL Query Examples, cont’d
Who are John Lane’s students and in which subjects?

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
Student_Class
+-------+-------+----------------------+
| first | last | subject
|
+-------+-------+----------------------+
| Tim
| Novak | Operating systems
|
| Kim
| Smith | Operating systems
|
| John | Doe
| Software engineering |
+-------+-------+----------------------+
Teacher
Class
Student_id
Class_code
1001
926
1001
951
1001
908
1005
974
1005
908
1014
931
1021
926
1021
974
1021
931
Student
Id
Last
First
Code
Teacher_id
Subject
Room
Id
Last
First
7003
Rogers
Tom
908
7008
Data structures
114
1001
Doe
John
7008
Thompson
Art
926
7003
Java programming
101
1005
Novak
Tim
7012
Lane
John
931
7051
Compilers
222
1009
Klein
Leslie
7051
Flynn
Mabel
951
7012
Software engineering
210
1014
Jane
Mary
974
7012
Operating systems
109
1021
Smith
Kim
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
21
XML Data

Data can also be stored as XML

XQuery is designed to query XML data


SQL : relational databases
XQuery : XML
_
Department of Computer Science
Fall 2011: October 31
CS 185C/286: History of Computing
© R. Mak
22
XQuery Examples
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
Department of Computer Science
Fall 2011: October 31
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Query:
What titles are in the bookstore?
doc("books.xml")/bookstore/book/title
Results:
<title
<title
<title
<title
lang="en">Everyday Italian</title>
lang="en">Harry Potter</title>
lang="en">XQuery Kick Start</title>
lang="en">Learning XML</title>
CS 185C/286: History of Computing
© R. Mak
23
XQuery Examples, cont’d
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
Department of Computer Science
Fall 2011: October 31
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Query:
Which books cost less than $30?
doc("books.xml")/bookstore/book[price<30]
Results:
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J.K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
CS 185C/286: History of Computing
© R. Mak
24
Related documents