File notes/lectures_notes.md changed (mode: 100644) (index da47295..ef28ac5) |
... |
... |
The focus will be on design, but we will have to do a little bit of everything. |
215 |
215 |
|
|
216 |
216 |
## Design |
## Design |
217 |
217 |
|
|
218 |
|
{#fig:cycle} |
|
|
218 |
|
{#fig:cycle} |
219 |
219 |
|
|
220 |
|
Refer to the ["The cycle of design" figure](#fig:cycle}. |
|
|
220 |
|
Refer to the ["The cycle of design" figure]{#fig:cycle}. |
221 |
221 |
|
|
222 |
222 |
Add a line from SQL to Program, a line from NoSQL to CLI. |
Add a line from SQL to Program, a line from NoSQL to CLI. |
223 |
223 |
Make the arrow from Bus. Statements to NoSQL dashed? |
Make the arrow from Bus. Statements to NoSQL dashed? |
|
... |
... |
If everything we knew about the campus came from that database, then |
437 |
437 |
|
|
438 |
438 |
## Concepts |
## Concepts |
439 |
439 |
|
|
440 |
|
 |
|
|
440 |
|
 |
441 |
441 |
|
|
442 |
442 |
The relational data model (or relational database schema) is: |
The relational data model (or relational database schema) is: |
443 |
443 |
|
|
|
... |
... |
We are dealing with moving aspects here: atributes on $1:1$, $1:N$, $N:1$ relati |
3531 |
3531 |
|
|
3532 |
3532 |
To determine cardinality ratio: fix all but one, wonder how many can be in that relationship. |
To determine cardinality ratio: fix all but one, wonder how many can be in that relationship. |
3533 |
3533 |
|
|
3534 |
|
{ width=100% } |
|
|
3534 |
|
{ width=100% } |
3535 |
3535 |
|
|
3536 |
|
{ width=100% } |
|
|
3536 |
|
{ width=100% } |
3537 |
3537 |
|
|
3538 |
3538 |
*Need to find a good $3$-ary example* |
*Need to find a good $3$-ary example* |
3539 |
3539 |
|
|
|
... |
... |
Two sorts of entity types: |
3552 |
3552 |
Weak (child) entity types are identified by **identifying / owner** type that is related to it, in conjunction with one attribute (**the partial key**). |
Weak (child) entity types are identified by **identifying / owner** type that is related to it, in conjunction with one attribute (**the partial key**). |
3553 |
3553 |
Relation is called identifiying relationship, and weak entities have a total participation constraint. |
Relation is called identifiying relationship, and weak entities have a total participation constraint. |
3554 |
3554 |
|
|
3555 |
|
{ width=100% } |
|
|
3555 |
|
{ width=100% } |
3556 |
3556 |
|
|
3557 |
3557 |
Choice between two representation: if pet is involved in other relationships! |
Choice between two representation: if pet is involved in other relationships! |
3558 |
3558 |
|
|
|
... |
... |
Choice between two representation: if pet is involved in other relationships! |
3564 |
3564 |
|
|
3565 |
3565 |
**Drawings** |
**Drawings** |
3566 |
3566 |
|
|
3567 |
|
{ width=100% } |
|
|
3567 |
|
{ width=100% } |
3568 |
3568 |
|
|
3569 |
|
{ width=100% } |
|
|
3569 |
|
{ width=100% } |
3570 |
3570 |
|
|
3571 |
3571 |
|
|
3572 |
3572 |
Crow's foot notation: |
Crow's foot notation: |
|
... |
... |
Closer to OO programming. |
3592 |
3592 |
|
|
3593 |
3593 |
From relational models to E.R. models (sometimes needed) |
From relational models to E.R. models (sometimes needed) |
3594 |
3594 |
|
|
3595 |
|
{ width=100% } |
|
|
3595 |
|
{ width=100% } |
3596 |
3596 |
|
|
3597 |
|
{ width=100% } |
|
|
3597 |
|
{ width=100% } |
3598 |
3598 |
|
|
3599 |
|
{ width=100% } |
|
|
3599 |
|
{ width=100% } |
3600 |
3600 |
|
|
3601 |
3601 |
--- |
--- |
3602 |
3602 |
|
|
|
... |
... |
c. Cross-Reference or Relationship Relation Approach: Create a lookup table with |
3634 |
3634 |
|
|
3635 |
3635 |
**Bogue: + Propagate option? Cascade, most of the time: weak entity type, lookup tables, etc.** |
**Bogue: + Propagate option? Cascade, most of the time: weak entity type, lookup tables, etc.** |
3636 |
3636 |
|
|
3637 |
|
{ width=100% } |
|
|
3637 |
|
{ width=100% } |
3638 |
3638 |
|
|
3639 |
3639 |
|
|
3640 |
3640 |
### Outro |
### Outro |
|
... |
... |
Att. 1 → Att. 3 | Att. 2 → Att. 1 |
3797 |
3797 |
Functional dependencies list the constraints between two sets of attributes from the database. |
Functional dependencies list the constraints between two sets of attributes from the database. |
3798 |
3798 |
X → Y reads "X fixes Y", and applier that values in Y are fixed by the value in X. |
X → Y reads "X fixes Y", and applier that values in Y are fixed by the value in X. |
3799 |
3799 |
|
|
3800 |
|
{ width=100% } |
|
|
3800 |
|
{ width=100% } |
3801 |
3801 |
|
|
3802 |
3802 |
|
|
3803 |
3803 |
Note that: |
Note that: |
|
... |
... |
For each attribute $A$ of the relation whose primary key is $A_1, …, A_n$: |
3884 |
3884 |
- Remove $A$ from the original relation |
- Remove $A$ from the original relation |
3885 |
3885 |
- Add a foreign key from $\{A'_1, …, A'_k\}$ to their original counterparts in the original relation. |
- Add a foreign key from $\{A'_1, …, A'_k\}$ to their original counterparts in the original relation. |
3886 |
3886 |
|
|
3887 |
|
{ width=100% } |
|
|
3887 |
|
{ width=100% } |
3888 |
3888 |
|
|
3889 |
3889 |
Refinment: note that if more than one attribute depends of the same subset $\{A'_1, …, A'_k\}$, we will create two relations: that is useless, we could have created just one. |
Refinment: note that if more than one attribute depends of the same subset $\{A'_1, …, A'_k\}$, we will create two relations: that is useless, we could have created just one. |
3890 |
3890 |
|
|
3891 |
|
{ width=100% } |
|
|
3891 |
|
{ width=100% } |
3892 |
3892 |
|
|
3893 |
3893 |
Note also that if our primary key is a singleton, then there is nothing to do, we are in 2NF as soon as we are in 1NF. |
Note also that if our primary key is a singleton, then there is nothing to do, we are in 2NF as soon as we are in 1NF. |
3894 |
3894 |
|
|
|
... |
... |
Wide, powerful, but also intimidating. |
3939 |
3939 |
|
|
3940 |
3940 |
You know UML from object-oriented programming language: |
You know UML from object-oriented programming language: |
3941 |
3941 |
|
|
3942 |
|
{ width=100% } |
|
|
3942 |
|
{ width=100% } |
3943 |
3943 |
|
|
3944 |
3944 |
That's a class diagram, there are other types of diagrams, they are not unrelated! |
That's a class diagram, there are other types of diagrams, they are not unrelated! |
3945 |
3945 |
For instance, using communication diagrams, deployment diagrams, and state chart diagrams, you can collect the requirements needed to draw a class diagram! |
For instance, using communication diagrams, deployment diagrams, and state chart diagrams, you can collect the requirements needed to draw a class diagram! |
|
... |
... |
They describe the behavioral, or dynamic, relationship, between components. |
3973 |
3973 |
- **State machine diagram**, a.k.a., state chart diagram, describes how a system react to external events. You can picture yourself a complex form of finite state automata diagram. |
- **State machine diagram**, a.k.a., state chart diagram, describes how a system react to external events. You can picture yourself a complex form of finite state automata diagram. |
3974 |
3974 |
- **Activity diagram** is a flow of control between activities. You may have seen them already, they are supposedly easy to follow: |
- **Activity diagram** is a flow of control between activities. You may have seen them already, they are supposedly easy to follow: |
3975 |
3975 |
|
|
3976 |
|
{ width=80% } |
|
|
3976 |
|
{ width=80% } |
3977 |
3977 |
|
|
3978 |
3978 |
Then there is the sub-category of "Interaction diagrams": |
Then there is the sub-category of "Interaction diagrams": |
3979 |
3979 |
|
|
|
... |
... |
Associations are, to some extend, more expressive than relationship types: |
4007 |
4007 |
- **As for relationship types** they can have attributes: actually, a whole class can be connected to an association. |
- **As for relationship types** they can have attributes: actually, a whole class can be connected to an association. |
4008 |
4008 |
- **As for relationship types**, they can express a cardinality constraint on the relation between classes. They are written as `min .. max`, with `*` for "no maximum", and the following shorthands: `*` stands for `0..*` and `1` stands for `1..1`. An association with `1` on one side and `*` on the other (resp. `1` and `1`, `*` and `1`, `*` and `*`) is sometimes called "one-to-many" (resp., "one-to-one", "many-to-one", "many-to-many"). The notation in partially inverted w.r.t. ER diagrams: |
- **As for relationship types**, they can express a cardinality constraint on the relation between classes. They are written as `min .. max`, with `*` for "no maximum", and the following shorthands: `*` stands for `0..*` and `1` stands for `1..1`. An association with `1` on one side and `*` on the other (resp. `1` and `1`, `*` and `1`, `*` and `*`) is sometimes called "one-to-many" (resp., "one-to-one", "many-to-one", "many-to-many"). The notation in partially inverted w.r.t. ER diagrams: |
4009 |
4009 |
|
|
4010 |
|
{ width=60% } |
|
|
4010 |
|
{ width=60% } |
4011 |
4011 |
|
|
4012 |
4012 |
- **As opposed to the relationship types**, they can have a direction, indicating that the user should be able to navigate them only in one direction, or in two (which is the default). This is used for security or privacy purposes. |
- **As opposed to the relationship types**, they can have a direction, indicating that the user should be able to navigate them only in one direction, or in two (which is the default). This is used for security or privacy purposes. |
4013 |
4013 |
- **As opposed to the relationship types**, they come in various flavors: |
- **As opposed to the relationship types**, they come in various flavors: |
|
... |
... |
Problem (Reading the MOVIES database ER schema) +.#movie |
4494 |
4494 |
Consider the ER schema for the MOVIES database ([@Textbook6, Figure 7.24]): |
Consider the ER schema for the MOVIES database ([@Textbook6, Figure 7.24]): |
4495 |
4495 |
|
|
4496 |
4496 |
\begin{tikzpicture} |
\begin{tikzpicture} |
4497 |
|
\node (a) at (0,0) {\includegraphics[page=1,width=1\textwidth]{images/te.pdf}}; |
|
|
4497 |
|
\node (a) at (0,0) {\includegraphics[page=1,width=1\textwidth]{img/te.pdf}}; |
4498 |
4498 |
\fill[white] (-8.3, 6.5) rectangle (-3.5, 4); |
\fill[white] (-8.3, 6.5) rectangle (-3.5, 4); |
4499 |
4499 |
\end{tikzpicture} |
\end{tikzpicture} |
4500 |
4500 |
|
|
|
... |
... |
A driver has an id, an age, a name, and an address. |
4531 |
4531 |
One of the interesting choice is: should "accident" be an entity type or a relationship type? |
One of the interesting choice is: should "accident" be an entity type or a relationship type? |
4532 |
4532 |
|
|
4533 |
4533 |
Solution +.# |
Solution +.# |
4534 |
|
~ \includegraphics[page=1,width=1\textwidth]{images/p.pdf} |
|
|
4534 |
|
~ \includegraphics[page=1,width=1\textwidth]{img/p.pdf} |
4535 |
4535 |
|
|
4536 |
4536 |
OR |
OR |
4537 |
4537 |
|
|
|
... |
... |
Java actually uses |
5289 |
5289 |
- A **protocol** (the API, a class libarary), Java DataBase Connectivity (JDBC), common to all DBMS. Essentially, a collection of classes to send SQL statements, retriev and update the results of a query, handle exceptions, etc. |
- A **protocol** (the API, a class libarary), Java DataBase Connectivity (JDBC), common to all DBMS. Essentially, a collection of classes to send SQL statements, retriev and update the results of a query, handle exceptions, etc. |
5290 |
5290 |
- A **subprotocol** (the driver, connector), Connector/J for MySQL. |
- A **subprotocol** (the driver, connector), Connector/J for MySQL. |
5291 |
5291 |
|
|
5292 |
|
{ height=50% } |
|
|
5292 |
|
{ height=50% } |
5293 |
5293 |
|
|
5294 |
5294 |
And the routine is a bit more complex: |
And the routine is a bit more complex: |
5295 |
5295 |
|
|