university of houston–clear lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · web...

24
2/4/2019 Xampp:

Upload: others

Post on 25-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

2/4/2019

Xampp:

Page 2: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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]

Page 3: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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

Page 4: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

Shift-right mouse to open command line prompt in the right location:

Page 5: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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

Page 6: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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)

Page 7: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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)

Page 8: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

[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.

Page 9: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

[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.

Page 10: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table
Page 11: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

All student info with lastname starts with C.

Xampp:

Page 12: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

MySQL COmmnad Line Prompt

C:\Users\yue>mysql -u yue -p

Enter password: ********

Usual location:

Ensure that it is in the PATH env. Var.

Page 13: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table
Page 14: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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)

Page 15: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

1/28/2019

Page 16: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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.

Page 17: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

stuId is a string of 6 characters:

Page 18: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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)

Page 19: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

PK of faculty: facId

Page 20: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

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:

Page 21: University of Houston–Clear Lakedcm.uhcl.edu/yue/courses/csci4333/spring2019/demo/… · Web viewfrom -- [a]  conceptually join to form a large table

[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'));