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