university of houston–clear lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · web...
TRANSCRIPT
2/4/2019
Xampp:
Mysql command line client: C:\xampp\mysql\bin\mysql.exe
C:\xampp\mysql\bin\ out into PATH variable.
Problem:
(c) List all student names, their minors, class numbers, class instructors and grades. The result:
[1] Expected Result:
[2] Analysis:
[a] Source tables: Student, Faculty, Department, Enroll (from output column needs), class (to find out facId of instructor)[b] Conditions:
Problem condition: ‘Linking’ conditions: FK = PK: (done by MS Access), equality of common attributes [def 2]
o (1) student(minor) = department(deptCode) (satisfy common attribute def [2] but not [1]
o (2) Student(StuId) = Enroll(StuId)o (3) Enroll(classNumber) = Class(classNumber)o (4) Class(facId) = faculty(facId)
common attributes
1. Same column names2. Columns with same semantic meaning
[c] Output columns:
Student(lastname, firstname) Minor: department(deptName) Enroll(classNumber, grade) Instructor: faculty(name)
select distinct – [c] <<result_columns>>
from -- [a] <<source_tables>> conceptually join to form a large table
where -- [b] <<conditions_for_inclusion>>
Shift-right mouse to open command line prompt in the right location:
Problem:
(a) List the last names and first names of students minoring in CSCI and having 'F110' as faculty advisor.
Expected:
+----------+-----------+| lastName | firstName |+----------+-----------+| McCarthy | Owen || Jones | Mary |+----------+-----------+2 rows in set (0.03 sec)
Analysis:
[a] sources: student
[b] condition: problem logic: minor = ‘CSCI’, advisor = ‘F110’
[c] output: lastName, firstName
(b) List the last names, first names, number of credits, and faculty advisor id of students having 'F110' or 'F115' as faculty advisor.
+----------+-----------+---------+---------+| lastName | firstName | credits | advisor |+----------+-----------+---------+---------+| Smith | Tom | 90 | F115 || Chin | Ann | 36 | F110 || Lee | Perry | 3 | F115 || McCarthy | Owen | 0 | F110 || Jones | Mary | 42 | F110 |+----------+-----------+---------+---------+5 rows in set (0.00 sec)
Analysis:
[a] sources: student
[b] condition: problem logic: advisor = 'F110' or 'F115'[c] output: lastName, firstName credits, advisor
1/30/2019
(b) All student names, their advisor names, and the major department names. The result:
[1] Expected Result:
[2] Analysis:
[a] Source tables: Student, Faculty, Department[b] Conditions:
Problem condition: ‘Linking’ conditions: FK = PK: (done by MS Access)
o (1) student(major) = department(deptCode)o (2) Student(advisor) = faculty(facId)
[c] Output columns:
Student(lastname, firstname) Advisor: Faculty(name) [column name:column value] Major: department(deptName)
Note that there are only two links needed to connect three tables. Need to remove two FK-PK links.
(c) List all student names, their minors, class numbers, class instructors and grades. The result:
[1] Expected Result:
[2] Analysis:
[a] Source tables: Student, Faculty, Department, Enroll (from output column needs), class (to find out facId of instructor)
[b] Conditions:
Problem condition: ‘Linking’ conditions: FK = PK: (done by MS Access), equality of common attributes [def 2]
o (1) student(minor) = department(deptCode) (satisfy common attribute def [2] but not [1]
o (2) Student(StuId) = Enroll(StuId)o (3) Enroll(classNumber) = Class(classNumber)o (4) Class(facId) = faculty(facId)
common attributes
3. Same column names4. Columns with same semantic meaning
[c] Output columns:
Student(lastname, firstname) Minor: department(deptName) Enroll(classNumber, grade) Instructor: faculty(name)
(d) After the user entered ‘C’ and hit ‘OK’, it shows information of students with last names starting with a ‘C’. When the query is executed, Access will show a pop-up window for the user to enter a character, which will be used to search for student last names that starts with this character.
[1] Expected Result:
[2] Analysis:
[a] Source tables: Student, Faculty (2: advisor, instructor), Enroll (from output column needs), class (to find out facId of instructor)
[b] Conditions:
Problem condition: ‘Linking’ conditions: FK = PK: (done by MS Access), equality of common attributes [def 2]
o (1) student(minor) = department(deptCode) (satisfy common attribute def [2] but not [1]
o (2) Student(StuId) = Enroll(StuId)o (3) Enroll(classNumber) = Class(classNumber)o (4) Class(facId) = faculty(facId)
common attributes
5. Same column names6. Columns with same semantic meaning
[c] Output columns:
Student(lastname, firstname) advisor: faculty(name) Enroll(classNumber, grade) Instructor: faculty(name)
Breakdown problem:
Find the student with last name input by the user.
All student info with lastname starts with C.
Xampp:
MySQL COmmnad Line Prompt
C:\Users\yue>mysql -u yue -p
Enter password: ********
Usual location:
Ensure that it is in the PATH env. Var.
MariaDB [(none)]> use c4333u;
Database changed
MariaDB [c4333u]> select * from class;
+-------------+-------+----------+------+
| classNumber | facId | schedule | room |
+-------------+-------+----------+------+
| ART103A | F101 | MWF9 | H221 |
| CSC201A | F105 | TuThF10 | M110 |
| CSC203A | F105 | MThF12 | M110 |
| HST205A | F115 | MWF11 | H221 |
| MTH101B | F110 | MTuTh9 | H225 |
| MTH103C | F110 | MWF11 | H225 |
| PHY333A | F230 | MWF3 | H225 |
+-------------+-------+----------+------+
7 rows in set (0.03 sec)
1/28/2019
A database is composed of a collection of tables (relations).
A table contains many rows (tuples) and columns (attributes) Each row contains many column values. Every row of a table has the same columns.
Values of the same column have the same data type.
stuId is a string of 6 characters:
SQL is the defacto language for accessing RDBMS.
In Enroll(StuId, ClassNumber, Grade):
FK: StuId references Student(StuId): parent table: Student
FK: ClassNUmber references Class(ClassNumber)
Problem:
The faculty names, the class numbers of the classes they taught of all faculty.
[1] Expected Results:
Adams, (with Fid F101) ART103ATanaka (F105), CSC201ATanaka (F105), CSC203A
…
[2] Analysis:
[a] Source tables: faculty (e.g. Adam, F101), class (e.g. ART103A)[b] Conditions:
Problem condition: ‘Linking’ condition: FK = PK: facId in Class (FK in child table) = facID in faculty (PK in parent table):
automatically done by MS Access.
[c] Output columns: faculty(name), class(classNumber)
PK of faculty: facId
PK of class: classNumber
ClassNumber: facId is a FK referenceing faculty(facId)
SELECT faculty.name, class.classNumber
FROM faculty INNER JOIN class ON faculty.facId = class.facId;
Problem:
The faculty names, the class numbers of the classes they taught, and the students and grades in these classes. Only include faculty that is of the rank Professor.
[1] Expected Results: (test-driven software engineering)
…
[2] Analysis:
[a] Source tables: faculty (e.g. Adam, F101), class (e.g. ART103A), enroll (S1001, A)[b] Conditions:
Problem condition: rank Professor. ‘Linking’ conditions: FK = PK: (1) facId in Class (FK in child table) = facID in faculty (PK in parent
table): automatically done by MS Access. (2) Enroll (ClassNumber) (FK) references Class(ClassNumber)
[c] Output columns: faculty(name), class(classNumber), enroll(stuId), enroll(grade)
SELECT faculty.name, class.classNumber, enroll.stuId, enroll.grade
FROM (faculty INNER JOIN class ON faculty.facId = class.facId) INNER JOIN enroll ON class.classNumber = enroll.classNumber
WHERE (((faculty.rank)='Professor'));