List of commits:
Subject Hash Author Date (UTC)
Preparing homework 5 2b9ba64d1d36ae9f413929947cac5e6cddceb3dc aubert@math.cnrs.fr 2019-03-01 20:06:12
Some fixes and added quiz #3. d73c356f1bec9679f7123bc508c1863f8de40aef aubert@math.cnrs.fr 2019-02-28 20:34:04
Working on solutions for problems in Chapter 3. 0da378f97cea97fa2b3614f1b611a3b5bdf42632 aubert@math.cnrs.fr 2019-02-26 19:56:23
Forgot one exercise in exam. 611bbe4cc68f802bfffd7bdfc70c3433a70eceb5 aubert@math.cnrs.fr 2019-02-22 20:39:07
Quick fix c22751b88c377a40dd2c037a706409aa29ef3ce2 aubert@math.cnrs.fr 2019-02-22 20:37:21
Various editing, fixing some of the solutions in Chapter 3 and some of the exercises in Chapter 4. 1e1d8dd576329b20aa3b7f9344aaecb9d11fc6f4 aubert@math.cnrs.fr 2019-02-22 20:22:09
Added the rest of the first exam for Fall 2019. 0d5a839282b1ae6e6c07e7b12a74ff2f0f2f3b86 aubert@math.cnrs.fr 2019-02-22 20:03:02
Adding a problem and its solution, in the SQL chapter. d5bfcbb949a6acac68156a8b37d6f8d23375b1cb aubert@math.cnrs.fr 2019-02-19 19:53:27
Adding second quiz, and fixing some exercises and problems in Chapter 3. 062c9b46fad52848efbf61e08c91103c0bae4127 aubert@math.cnrs.fr 2019-02-06 20:04:16
Clarification on SQL constraints. 70e26a02aa344cc1bf009a089623be6baac79ba7 aubert@math.cnrs.fr 2019-01-29 22:46:26
Adding some minor SQL remarks + code for HW_FACULTY. 1d1b74302d29fb63c3c2bacca30533283f720997 aubert@math.cnrs.fr 2019-01-25 17:24:16
fixing small typo. 0feeb8df61e05d6d0990120628303cf31108f100 aubert@math.cnrs.fr 2019-01-22 18:23:34
Quick fix + adding macOS install instructions. ea3063e4e9225c8ce66838c8bfddb9a34aadacf8 aubert@math.cnrs.fr 2019-01-16 15:59:38
Fixing a few typos and adding a drawing. b335800d4129c8e29763a6c1d564243d485fa51b aubert@math.cnrs.fr 2019-01-15 19:03:38
Fixing first homework 3eeb05a78235274a330c780f4f26b5fed1a01aef aubert@math.cnrs.fr 2019-01-08 19:50:29
Added content of various exam, fixed intro, added references, solutions, fixed types. a8e9d2d4856133d68d882403cde42dfcc2f5cc69 aubert@math.cnrs.fr 2019-01-07 16:47:02
Cleaning files and makefile 7605a6530505ad69042413dd995d77f1814c2f30 au 2018-12-24 14:25:31
Fixed margin for PDF, added a couple of SVG images, fixed some problems, added some code. eb83d9f07d738df7ab2515b768d6165a3b7e5ca3 au 2018-12-24 02:28:36
Working on rel_mod for Prof_Department_Extended. 2b1eff83797fbda620189f014043d648c884e887 au 2018-12-23 22:38:07
Working on FD and various figures. 8fd7f8322e70ae252596aa9cb88918ac40d5aa84 au 2018-12-23 20:25:19
Commit 2b9ba64d1d36ae9f413929947cac5e6cddceb3dc - Preparing homework 5
Author: aubert@math.cnrs.fr
Author date (UTC): 2019-03-01 20:06
Committer name: aubert@math.cnrs.fr
Committer date (UTC): 2019-03-01 20:06
Parent(s): d73c356f1bec9679f7123bc508c1863f8de40aef
Signing key:
Tree: bd6a2a490ef83a6311bf521970ef932c6b1deeec
File Lines added Lines deleted
notes/lectures_notes.md 72 49
File notes/lectures_notes.md changed (mode: 100644) (index 5558261..55fe01b)
... ... The following links could be useful:
1948 1948 - <https://dev.mysql.com/doc/refman/5.7/en/connecting-disconnecting.html> - <https://dev.mysql.com/doc/refman/5.7/en/connecting-disconnecting.html>
1949 1949 - <https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-debian-8> - <https://www.linode.com/docs/databases/mysql/how-to-install-mysql-on-debian-8>
1950 1950
1951 #### Installing MySQL on Windows 10
1951 #### Installing MySQL on Windows 10 {#sec:install_win}
1952 1952
1953 1953 #. Visit <https://dev.mysql.com/downloads/installer/>, click on "Download" next to #. Visit <https://dev.mysql.com/downloads/installer/>, click on "Download" next to
1954 1954
 
... ... The following links could be useful:
1957 1957 where XXX is a number version (e.g., 8.0.13.0.), and YYY is the size of the file (e.g., 16.3M). On the next page, click on the (somewhat hidden) "No thanks, just start my download." button. where XXX is a number version (e.g., 8.0.13.0.), and YYY is the size of the file (e.g., 16.3M). On the next page, click on the (somewhat hidden) "No thanks, just start my download." button.
1958 1958 #. Save the "mysql-installer-web-community-XXX.msi" file, and open it. If there is an updated version of the installer available, agree to download it. Accept the license term. #. Save the "mysql-installer-web-community-XXX.msi" file, and open it. If there is an updated version of the installer available, agree to download it. Accept the license term.
1959 1959 #. We will now install the various components needed for this class, leaving all the choices by defaults. This means that you need to do the following: #. We will now install the various components needed for this class, leaving all the choices by defaults. This means that you need to do the following:
1960 #. Leave the first option on "Developer Default" and click on "Next"
1960 #. Leave the first option on "Developer Default" and click on "Next", or click on "Custom", and select the following:
1961 ![](img/mysql_install.png)
1961 1962 #. Click on "Next" even if you don't meet all the requirements #. Click on "Next" even if you don't meet all the requirements
1962 1963 #. Click on "Execute". The system will download and install several softwares (this may take some time). #. Click on "Execute". The system will download and install several softwares (this may take some time).
1963 1964 #. Click on "Next" twice, leave "Type and Networking" on "Standalone MySQL Server / Classic MySQL Replication" and click "Next", and leave the next options as they are (unless you know what you do and want to change the port, for instance) and click on "Next". #. Click on "Next" twice, leave "Type and Networking" on "Standalone MySQL Server / Classic MySQL Replication" and click "Next", and leave the next options as they are (unless you know what you do and want to change the port, for instance) and click on "Next".
1964 #. \label{choose-pswd} You now need to choose a password for the MySQL root account.
1965 #. You now need to choose a password for the MySQL root account.
1965 1966 It can be anything, just make sure to memorize it. It can be anything, just make sure to memorize it.
1966 1967 Click on "Next". Click on "Next".
1967 1968 #. On the "Windows Service" page, leave everything as it is and click on "Next". #. On the "Windows Service" page, leave everything as it is and click on "Next".
 
... ... Choice between two representation: if pet is involved in other relationships!
3851 3852
3852 3853 ### Alternative notation ### Alternative notation
3853 3854
3854 **Drawings**
3855 #### Notation With Explicit Maximal
3855 3856
3856 3857 ![](img/Entity_Alt_notation01.jpeg) ![](img/Entity_Alt_notation01.jpeg)
3857 3858
3858 3859 ![](img/Entity_Alt_notation02.jpeg) ![](img/Entity_Alt_notation02.jpeg)
3859 3860
3860 Crow's foot notation:
3861 #### Crow's foot notation {#sec:Crow_foot}
3861 3862
3862 3863 ![](img/ERD-Notation.PNG) ![](img/ERD-Notation.PNG)
3863 3864
 
... ... Crow's foot notation:
3867 3868
3868 3869 <https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow%27s_foot_notation> <https://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model#Crow%27s_foot_notation>
3869 3870
3870 ### Enhanced Entity–Relationship Model
3871 ### Enhanced Entity–Relationship Model {#sec:EER}
3871 3872
3872 3873 Extended (or Enhanced) E.R. Models (E.E.R.) have additionaly: Extended (or Enhanced) E.R. Models (E.E.R.) have additionaly:
3873 3874
 
... ... Extended (or Enhanced) E.R. Models (E.E.R.) have additionaly:
3876 3877
3877 3878 Closer to object-oriented programming. Closer to object-oriented programming.
3878 3879
3880 <!--
3881 Ressources:
3882 - https://www.ibm.com/developerworks/library/ws-mapping-to-rdb/
3883 - https://stackoverflow.com/questions/1567935/how-to-do-inheritance-modeling-in-relational-databases
3884
3885 I would love to have an exercise based on that:
3886
3887 - https://dba.stackexchange.com/questions/120176/representing-a-superclass-subclass-or-supertype-subtype-relationship-in-a-mysq
3888
3889 to show how close we can get to having a "generalization/specialization" "superclass/subclass" .
3890
3891 Won't be able to represent it, because of https://stackoverflow.com/a/21260267/2657549
3892
3893 -->
3894
3879 3895 ### Reverse Engineering ### Reverse Engineering
3880 3896
3881 3897 From relational models to E.R. models (sometimes needed) From relational models to E.R. models (sometimes needed)
 
... ... Problem (ER diagram for car insurance) +.#car-insurance
4890 4906
4891 4907 --- ---
4892 4908
4909 Problem (Reverse engineering by hand) +.#Reverse-Engineering-ACTOR
4910 ~
4911
4912 Look at the following relational model, and "reverse-engineer" it to obtain an E.R. diagram:
4913
4914 ![](fig/rel_mod/ACTOR)
4915
4916 ---
4917
4918
4919 Problem (Discovering MySQL Workbench) +.#mysqlw
4920 ~
4921
4922 In this problem, we will install and explore the basic functionalities of MySQL Workbench, which is a cross-platform, open-source, and free graphical interface for database design.
4923
4924 #. Install MySQL Workbench if needed. Maybe you already included it in the packages to instaLl when you installed MySQL (cf. [the instructions to install MySQL on Windows](#sec:install_win)): try to find if this is the case before trying to install it.
4925 Otherwise, use your package manager, or download the binaries from <https://dev.mysql.com/downloads/workbench/>.
4926 The installation should be straightforward for all operating system.
4927 #. Once installed, execute the software. The instructions below were tested for the 6.3.8 version on Debian, and 8.0.15 version on Windows. The trouble with GUI-software is that the menus may differ slightly with what you see, but the core tools we will be using should still be there, and under a similar name, if not the same.
4928 #. Under the panel "MySQL Connections", you should see your local installation listed as "Local instance 3306". Click on the top-right corner of that box, and then on "Edit Connections". Alternatively, click on "Database", on "Manage Connections", and then on "Local instance 3306".
4929 #. Check that all the parameters are correct. Normally, you only have to change the name of the user to "testuser", and leave the rest as it is. Click on "Test the connection", and enter your password (which should be "password") when prompted. If you receive a warning about "Incompatible/nonstandard server version or connection protocol detected", click on "Continue anyway".
4930 #. Now, click on the box "Local instance 3306", and enter your password. A new tab appears, you can see the list of schemas in the bottom part of the left panel.
4931 #. Click on "Database", and then on "Reverse Engineering" (or hit `ctrl` + `r`), click on "next", enter your password, and click on "next". You should see the list of the schemas stored in your database. Select one (any one, we are just exploring the functionalities at that point, you can pick for instance `HW_DB_COFFEE` from [%D %n (%T)](#problem:coffee)), click on "next", and then click on "execute", "next", and "close".
4932 #. You're back on the previous view, but you should now see "E.E.R. diagram" on the top of the middle panel. Click on "E.E.R. diagram" twice, scroll down if needed, and you should see the E.E.R. diagram.
4933 #. This diagram isn't exaclty an E.R. diagram, and it is not a U.M.L. diagram either: it is an [E.E.R. diagram](#sec:EER), that uses [Crow's foot notation](#sec:Crow_foot). Make sure you understand it.
4934 #. Try to modify the E.E.R. diagram. Make some relations mandatory, change their name, add an attribute, change the name of another, insert a couple of elements in an entity, add a row in a table, etc. Make sure you understand the meaning of the lines between the entities.
4935 #. Once you're done, try to "Forward Engineer" by hitting "Ctrl" + "G". Click on "next" twice, enter your password, click on lick on "next" once more, and you should see the `SQL` code needed to produce the table you just designed using the graphical tool.
4936
4937 ---
4938
4893 4939 Problem (ER-to-Relation mapping for car insurance) +.#ERtoREL Problem (ER-to-Relation mapping for car insurance) +.#ERtoREL
4894 4940 ~ ~
4895 4941
4896 Apply the ER-to-Relation mapping to your ER diagram from the previous problem.
4942 Apply the ER-to-Relation mapping to your ER diagram from [%D %n (%T)](#problem:car-insurance).
4897 4943
4898 4944 --- ---
4899 4945
 
... ... Problem (ER-to-Relation mapping for Country) +.#ERtoRELCountry
4916 4962
4917 4963 --- ---
4918 4964
4965
4966 Problem (From business statements to E.R. diagram -- UNIVERSITY) +.#BusinessToEr
4967 ~
4968
4969 Consider the following requirements for a UNIVERSITY database, used to keep track of students' transcripts.
4970
4971 #. The university keeps track of each student's name, student number, class (freshman, sophomore, …, graduate), major department, minor department (if any), and degree program (B.A., B.S., …, Ph.D.).
4972 Student number has unique values for each student.
4973 #. Each department is described by a name and has a (unique) department code.
4974 #. Each course has a course name, a course number, credit hours, and is offered by at least one department. The value of course number is unique for each course. A course has at least one section.
4975 #. Each section of a course has an instructor, a semester, a year, and a section number.
4976 The section number distinguishes different sections of the same course that are taught during the same semester/year; its values are 1, 2, 3, …, up to the number of sections taught during each semester. Students can enroll in sections and receive a letter grade, and grade point (0, 1, 2, 3, 4 for F, D, C, B, A, respectively).
4977
4978 Draw an E.R. diagram for that schema.
4979 Specify key attributes of each entity type and structural constraints on each relationship type.
4980 Note any unspecified requirements, and make appropriate assumptions to make the specification complete.
4981
4982 ---
4983
4919 4984 Problem (Normal form of a CAR\_SALE relation) +.#carsale Problem (Normal form of a CAR\_SALE relation) +.#carsale
4920 4985 ~ ~
4921 4986
 
... ... Author\_name | → | Author\_affil
5024 5089
5025 5090 --- ---
5026 5091
5027 Problem (From business statements to E.R. diagram -- UNIVERSITY) +.#BusinessToEr
5028 ~
5029
5030 Consider the following requirements for a UNIVERSITY database, used to keep track of students' transcripts.
5031
5032 #. The university keeps track of each student's name, student number, class (freshman, sophomore, …, graduate), major department, minor department (if any), and degree program (B.A., B.S., …, Ph.D.).
5033 Student number has unique values for each student.
5034 #. Each department is described by a name and has a (unique) department code.
5035 #. Each course has a course name, a course number, credit hours, and is offered by at least one department. The value of course number is unique for each course. A course has at least one section.
5036 #. Each section of a course has an instructor, a semester, a year, and a section number.
5037 The section number distinguishes different sections of the same course that are taught during the same semester/year; its values are 1, 2, 3, …, up to the number of sections taught during each semester. Students can enroll in sections and receive a letter grade, and grade point (0, 1, 2, 3, 4 for F, D, C, B, A, respectively).
5038
5039 Draw an E.R. diagram for that schema.
5040 Specify key attributes of each entity type and structural constraints on each relationship type.
5041 Note any unspecified requirements, and make appropriate assumptions to make the specification complete.
5042
5043 ---
5044 5092
5045 5093 Problem (From UML to relational model -- DRIVER) +.#UMLtoRELDriver Problem (From UML to relational model -- DRIVER) +.#UMLtoRELDriver
5046 5094 ~ ~
 
... ... Problem (From E.R. to relational schema and UML class diagram -- CAR\_INFO) +.#c
5114 5162
5115 5163 --- ---
5116 5164
5117 Problem (Discovering MySQL Workbench) +.#mysqlw
5118 ~
5119
5120 In this exercise, we will install and explore the basic functionalities of MySQL Workbench, which is a cross-platform, open-source, and free graphical interface for database design.
5121
5122 #. Install MySQL Workbench: use your package manager, or download the binaries from <https://dev.mysql.com/downloads/workbench/>.
5123 #. Once installed, execute the software. Under the panel "MySQL Connections", you should see your local installation listed as "Local instance 3306". Click on the top-right corner of that box, and then on "Edit Connections". Alternatively, click on "Database", on "Manage Connections", and then on "Local instance 3306".
5124 #. Check that all the parameters are correct. Normally, you only have to change the name of the user to "testuser", and leave the rest as it is. Click on "Test the connection", and enter your password (which should be "password") when prompted. If you receive a warning about "Incompatible/nonstandard server version or connection protocol detected", click on "Continue anyway".
5125 #. Now, click on the box "Local instance 3306", and enter your password. A new tab appears, you can see the list of schemas in the bottom part of the left panel.
5126 #. Click on "Database", and then on "Reverse Engineering" (or hit `ctrl` + `r`), click on "next", enter your password, and click on "next". You should see the list of the schemas stored in your database. Select one (any one, we are just exploring the functionalities at that point), click on "next", and then click on "execute", "next", and "close".
5127 #. You're back on the previous view, but you should now see "E.E.R. diagram" on the top of the middle panel. Click on "E.E.R. diagram" twice, scroll down if needed, and you should see the E.E.R. diagram.
5128 #. This diagram isn't exaclty an E.R. diagram, and it is not a U.M.L. diagram either. Yet, you should still be able to understand parts of it, and should try to modify it. Make some relations mandatory, change their name, add an attribute, change the name of another, insert a couple of elements in an entity, add a row in a table, etc. Make sure you understand the meaning of the lines between the entities.
5129 #. Once you're done, try to "Forward Engineer" by hitting "Ctrl" + "G". Click on "next" twice, enter your password, click on lick on "next" once more, and you should see the `SQL` code needed to produce the table you just designed using the graphical tool.
5130
5131 ---
5132
5133 5165 Problem (Using MySQL Workbench's reverse engineering) +.#reverseeng Problem (Using MySQL Workbench's reverse engineering) +.#reverseeng
5134 5166 ~ ~
5135 5167
 
... ... Problem (From business statements to dependencies -- KEYBOARD) +.#BusinessToDepe
5161 5193 #. Based on those statements, what could be a key for this relation? #. Based on those statements, what could be a key for this relation?
5162 5194 #. Assuming all those functional dependencies hold, and taking the primary key you identified at the previous step, what is the degree of normality of this relation? Justify your answer. #. Assuming all those functional dependencies hold, and taking the primary key you identified at the previous step, what is the degree of normality of this relation? Justify your answer.
5163 5195
5164 ---
5165
5166 Problem (Reverse engineering by hand) +.#Reverse-Engineering-ACTOR
5167 ~
5168
5169 Look at the following relational model, and "reverse-engineer" it to obtain an E.R. diagram:
5170
5171 ![](fig/rel_mod/ACTOR)
5172
5173 5196
5174 5197 ## Solution to Selected Problems {-} ## Solution to Selected Problems {-}
5175 5198
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/caubert/CSCI_3410

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/caubert/CSCI_3410

Clone this repository using git:
git clone git://git.rocketgit.com/user/caubert/CSCI_3410

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main