|
|
Example:
|
|
|
Grade Report Financial record (other files) |
|
|
|
One man said it's like a tree trunk (he felt the feet)
|
|
|
|
How to achieve Logical Data Independence:
|
NOTE:
To achieve Logical Data Independence, we need to "do something" - specifically: run a program to put the data into the desired format !
| Name | Course | Course Name | Semester | Grade |
|---|---|---|---|---|
| James Bond | CS170 | Intro to CS | Fall 1997 | B- |
| James Bond | CS255 | Assembler programming | Fall 1998 | B+ |
| James Bond | CS355 | Computer Architecture | Spring 1999 | C+ |
| John Doe | CS170 | Intro to CS | Spring 2000 | A- |
| John Doe | CS255 | Assembler programming | Fall 2001 | C+ |
| John Doe | CS355 | Computer Architecture | Spring 2002 | D+ |
As you can see, the data is highly redundant:
| ID | Name |
|---|---|
| 007 | James Bond |
| 123 | John Doe |
| CID | Course Number | Name |
|---|---|---|
| 1542 | CS170 | Intro to CS |
| 8726 | CS255 | Assembler Programming |
| 8976 | CS355 | Computer Architecture |
| ID | CID | Semester | Grade |
|---|---|---|---|
| 007 | 1542 | Fall 1997 | B- |
| 007 | 8726 | Fall 1998 | B+ |
| 007 | 8976 | Spring 1999 | C+ |
| 123 | 1542 | Spring 2000 | A- |
| 123 | 8726 | Fall 2001 | C+ |
| 123 | 8976 | Spring 2002 | D+ |
NOTE:
|
(When I discuss the mapping operation, I will remind you of this material.. - promise :-))
|
(See: 377/Syllabus/1-files/Logical-Data-Depend)
>> mysql -h 192.168.1.20 -u cheung -p (w04h)
>> use LogDataIndep
mysql> show tables;
+-----------------------+
| Tables_in_cs377_teach |
+-----------------------+
| course |
| gradereport |
| student |
+-----------------------+
mysql> select * from student;
+------+------------+
| id | name |
+------+------------+
| 007 | James Bond |
| 123 | John Doe |
+------+------------+
mysql> select * from course;
+------+---------+-----------------------+
| cid | cnumber | cname |
+------+---------+-----------------------+
| 1542 | CS170 | Intro to CS |
| 8762 | CS255 | Assembler Programming |
| 8976 | CS355 | Computer Architecture |
+------+---------+-----------------------+
mysql> select * from gradereport;
+------+------+------------+-------+
| id | cid | semester | grade |
+------+------+------------+-------+
| 007 | 1542 | Fall 1997 | B- |
| 007 | 8762 | Fall 1998 | B+ |
| 007 | 8976 | Spring 199 | C+ |
| 123 | 1542 | Spring 200 | A- |
| 123 | 8762 | Fall 2001 | C+ |
| 123 | 8976 | Spring 200 | D+ |
+------+------+------------+-------+
|
select name, cnumber, cname, semester, grade
from student, course, gradereport
where student.id = gradereport.id
and course.cid = gradereport.cid;
+------------+---------+-----------------------+------------+-------+
| name | cnumber | cname | semester | grade |
+------------+---------+-----------------------+------------+-------+
| James Bond | CS170 | Intro to CS | Fall 1997 | B- |
| James Bond | CS255 | Assembler Programming | Fall 1998 | B+ |
| James Bond | CS355 | Computer Architecture | Spring 199 | C+ |
| John Doe | CS170 | Intro to CS | Spring 200 | A- |
| John Doe | CS255 | Assembler Programming | Fall 2001 | C+ |
| John Doe | CS355 | Computer Architecture | Spring 200 | D+ |
+------------+---------+-----------------------+------------+-------+
|
create view my_report(stud_name, course_number, course_name, semester, grade)
as
(select name, cnumber, cname, semester, grade
from student, course, gradereport
where student.id = gradereport.id
and course.cid = gradereport.cid);
Query OK, 0 rows affected (0.03 sec)
|
We have a new table in the data base:
mysql> show tables;
+-----------------------+
| Tables_in_cs377_teach |
+-----------------------+
| course |
| gradereport |
| my_report |
| student |
+-----------------------+
|
mysql> select * from my_report; +------------+---------------+-----------------------+-------------+-------+ | stud_name | course_number | course_name | semester | grade | +------------+---------------+-----------------------+-------------+-------+ | James Bond | CS170 | Intro to CS | Fall 1997 | B- | | James Bond | CS255 | Assembler Programming | Fall 1998 | B+ | | James Bond | CS355 | Computer Architecture | Spring 1999 | C+ | | John Doe | CS170 | Intro to CS | Spring 2000 | A- | | John Doe | CS255 | Assembler Programming | Fall 2001 | C+ | | John Doe | CS355 | Computer Architecture | Spring 2002 | D+ | +------------+---------------+-----------------------+-------------+-------+ mysql> select * from my_report where stud_name='James Bond'; +------------+---------------+-----------------------+-------------+-------+ | stud_name | course_number | course_name | semester | grade | +------------+---------------+-----------------------+-------------+-------+ | James Bond | CS170 | Intro to CS | Fall 1997 | B- | | James Bond | CS255 | Assembler Programming | Fall 1998 | B+ | | James Bond | CS355 | Computer Architecture | Spring 1999 | C+ | +------------+---------------+-----------------------+-------------+-------+ |
select student.id, name, count(cid) from student, gradereport where student.id = gradereport.id group by student.id, name; |
This create a new view:
create view view2 as
(select student.id, name, count(cid)
from student, gradereport
where student.id = gradereport.id
group by student.id, name);
|
|
|
Can we still obtain the same external schema ? In other words: can we still present the data in the same format as before to the user ? |
So we need to update the mapping operation if we change the conceptual schema |
|
Example:
|
|
|
|
The term logical refers to thefact that:
|