File notes/lectures_notes.md changed (mode: 100644) (index 4bc8dc8..d33f4de) |
... |
... |
Exercise +.#explainfk |
2281 |
2281 |
~ |
~ |
2282 |
2282 |
|
|
2283 |
2283 |
If `PkgName` is the primary key in the table `MYTABLE`, what can you tell about the number of rows returned by the following statement? |
If `PkgName` is the primary key in the table `MYTABLE`, what can you tell about the number of rows returned by the following statement? |
|
2284 |
|
|
2284 |
2285 |
`SELECT * FROM MYTABLE WHERE PkgName = 'MySQL';`{.sqlmysql}. |
`SELECT * FROM MYTABLE WHERE PkgName = 'MySQL';`{.sqlmysql}. |
2285 |
2286 |
|
|
2286 |
2287 |
Exercise +.# |
Exercise +.# |
|
... |
... |
Problem (TRAIN table and more advanced SQL coding) +.#train |
2943 |
2944 |
|
|
2944 |
2945 |
@problem:train -- Question -.# |
@problem:train -- Question -.# |
2945 |
2946 |
|
|
2946 |
|
: Write `INSERT` statements that insert one tuple of your invention in each relation. |
|
|
2947 |
|
: Write `INSERT` statements that insert one tuple of your invention in each relation (without `NULL` values). |
2947 |
2948 |
Your statements should respect all the constraints (including the ones we added at the previous questions) and result in actual insertions. (Remember that four digits is a valid value for an attribute with the `YEAR(4)` datatype.) |
Your statements should respect all the constraints (including the ones we added at the previous questions) and result in actual insertions. (Remember that four digits is a valid value for an attribute with the `YEAR(4)` datatype.) |
2948 |
2949 |
|
|
2949 |
2950 |
@problem:train -- Question -.# |
@problem:train -- Question -.# |
|
... |
... |
Solution to [%D %n (%T)](#problem:address) |
3258 |
3259 |
~~~ |
~~~ |
3259 |
3260 |
|
|
3260 |
3261 |
@problem:address -- Solution to Q. -.# |
@problem:address -- Solution to Q. -.# |
3261 |
|
~ |
|
|
3262 |
|
~ We have. |
3262 |
3263 |
|
|
3263 |
3264 |
 |
3278 |
3279 |
|
|
3279 |
3280 |
@problem:address -- Solution to Q. -.# |
@problem:address -- Solution to Q. -.# |
3280 |
3281 |
|
|
3281 |
|
: This syntax is better for "bulk insertion", since it allows to write less command, and to focus on the data to insert. |
|
|
3282 |
|
: This syntax is better for "bulk insertion", since it allows to write less command, and to focus on the data to insert. However, if an error occurs, then nothing gets inserted. |
3282 |
3283 |
|
|
3283 |
3284 |
@problem:address -- Solution to Q. -.# |
@problem:address -- Solution to Q. -.# |
3284 |
3285 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:repetition) |
3359 |
3360 |
|
|
3360 |
3361 |
CREATE TABLE EXAMPLE( |
CREATE TABLE EXAMPLE( |
3361 |
3362 |
X VARCHAR(15), |
X VARCHAR(15), |
3362 |
|
Y INT); |
|
|
3363 |
|
Y INT |
|
3364 |
|
); |
3363 |
3365 |
~~~ |
~~~ |
3364 |
3366 |
|
|
3365 |
3367 |
@problem:repetition -- Solution to Q. -.# |
@problem:repetition -- Solution to Q. -.# |
|
... |
... |
Solution to [%D %n (%T)](#problem:repetition) |
3390 |
3392 |
This is an illustration of the fact that a table in sql is *not* a set, as opposed to a relation in the relation model. |
This is an illustration of the fact that a table in sql is *not* a set, as opposed to a relation in the relation model. |
3391 |
3393 |
|
|
3392 |
3394 |
@problem:repetition -- Solution to Q. -.# |
@problem:repetition -- Solution to Q. -.# |
3393 |
|
~ |
|
|
3395 |
|
~ |
3394 |
3396 |
|
|
3395 |
3397 |
The command |
The command |
3396 |
3398 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:repetition) |
3430 |
3432 |
Solution to [%D %n (%T)](#problem:profrevisited) |
Solution to [%D %n (%T)](#problem:profrevisited) |
3431 |
3433 |
~ |
~ |
3432 |
3434 |
|
|
3433 |
|
We only give the relevant code for this problem: |
|
|
3435 |
|
For Question 1 and 5, we obtain: |
|
3436 |
|
|
|
3437 |
|
 |
3434 |
3443 |
|
|
|
3444 |
|
For the other questions, refer to this code. |
|
3445 |
|
|
3435 |
3446 |
```{.sqlmysql .numberLines include=code/sql/LECTURE.sql} |
```{.sqlmysql .numberLines include=code/sql/LECTURE.sql} |
3436 |
3447 |
``` |
``` |
3437 |
|
|
|
3438 |
|
--- |
|
3439 |
|
|
|
3440 |
3448 |
|
|
3441 |
3449 |
--- |
--- |
3442 |
3450 |
|
|
|
... |
... |
From relational models to E.R. models (sometimes needed) |
3864 |
3872 |
|
|
3865 |
3873 |
 |
 |
3866 |
3874 |
|
|
3867 |
|
 |
|
3868 |
|
|
|
3869 |
3875 |
 |
 |
3870 |
3876 |
|
|
|
3877 |
|
|
3871 |
3878 |
--- |
--- |
3872 |
3879 |
|
|
3873 |
3880 |
## E.R.-to-Relational Models Mapping |
## E.R.-to-Relational Models Mapping |
|
... |
... |
Exercise +.# |
4360 |
4367 |
|
|
4361 |
4368 |
Exercise +.# |
Exercise +.# |
4362 |
4369 |
|
|
4363 |
|
: What is a partial key? |
|
4364 |
|
|
|
4365 |
|
Exercise +.# |
|
4366 |
|
|
|
4367 |
4370 |
: For the following binary relationships, suggest cardinality ratios based on the common-sense meaning of the entity types. |
: For the following binary relationships, suggest cardinality ratios based on the common-sense meaning of the entity types. |
4368 |
4371 |
|
|
4369 |
4372 |
<!-- Bug with table --> |
<!-- Bug with table --> |
|
... |
... |
Exercise +.# |
4400 |
4403 |
|
|
4401 |
4404 |
Exercise +.# |
Exercise +.# |
4402 |
4405 |
|
|
|
4406 |
|
: What is a partial key? |
|
4407 |
|
|
|
4408 |
|
Exercise +.# |
|
4409 |
|
|
4403 |
4410 |
: Why do weak entity type have a total participation constraint? |
: Why do weak entity type have a total participation constraint? |
4404 |
4411 |
|
|
4405 |
4412 |
Exercise +.# |
Exercise +.# |
|
... |
... |
Solution +.# |
4590 |
4597 |
Solution +.# |
Solution +.# |
4591 |
4598 |
|
|
4592 |
4599 |
: A relationship type where the same entity type participates more than once. |
: A relationship type where the same entity type participates more than once. |
4593 |
|
On rooms, "is to the left of", on persons, "is married to". |
|
|
4600 |
|
On seats, "is to the left of", on persons, "is married to". |
4594 |
4601 |
|
|
4595 |
4602 |
Solution +.# |
Solution +.# |
4596 |
4603 |
|
|
|
... |
... |
Solution +.# |
4604 |
4611 |
|
|
4605 |
4612 |
: When the cardinality is $1:N$, $1:1$ or $N:1$. |
: When the cardinality is $1:N$, $1:1$ or $N:1$. |
4606 |
4613 |
|
|
4607 |
|
Solution +.# |
|
4608 |
|
|
|
4609 |
|
: For a weak entity attribute, it is the attribute that can uniquely identify weak entites that are related to the same owner entity. |
|
4610 |
|
|
|
4611 |
4614 |
Solution +.# |
Solution +.# |
4612 |
4615 |
~ |
~ |
4613 |
4616 |
|
|
|
... |
... |
INSTRUCTOR | $1:N$ | LECTURE | "An instructor can teach multiple lecture, but a |
4619 |
4622 |
INSTRUCTOR | $1:N$ | OFFICE | "An instructor can have multiple office, but an office belongs to only one instructor" |
INSTRUCTOR | $1:N$ | OFFICE | "An instructor can have multiple office, but an office belongs to only one instructor" |
4620 |
4623 |
COMPUTER | $M:N$ | OS| "A computer can have multiple operating system, the same operating system can be installed on more than one computer." |
COMPUTER | $M:N$ | OS| "A computer can have multiple operating system, the same operating system can be installed on more than one computer." |
4621 |
4624 |
|
|
4622 |
|
Some of those choices, of course, are is arguable (typically, almost any combination seems reasonnable for the INSTRUCTOR : OFFICE relation). |
|
|
4625 |
|
Some of those choices, of course, are arguable (typically, almost any combination seems reasonnable for the INSTRUCTOR : OFFICE relation). |
4623 |
4626 |
|
|
4624 |
4627 |
Solution +.# |
Solution +.# |
4625 |
4628 |
|
|
|
... |
... |
Solution +.# |
4640 |
4643 |
|
|
4641 |
4644 |
Solution +.# |
Solution +.# |
4642 |
4645 |
|
|
4643 |
|
: Same as before? |
|
|
4646 |
|
: To be written. |
|
4647 |
|
|
|
4648 |
|
Solution +.# |
|
4649 |
|
|
|
4650 |
|
: For a weak entity attribute, it is the attribute that can uniquely identify weak entites that are related to the same owner entity. |
4644 |
4651 |
|
|
4645 |
4652 |
Solution +.# |
Solution +.# |
4646 |
4653 |
|
|
|
... |
... |
The idea was to have |
4786 |
4793 |
|
|
4787 |
4794 |
- The `EXAM` table storing information about exams, |
- The `EXAM` table storing information about exams, |
4788 |
4795 |
- One entry per problem in the PROBLEM table, and to associate every problem to an exam, |
- One entry per problem in the PROBLEM table, and to associate every problem to an exam, |
4789 |
|
- The grade of one student for one particular exam stored in the `STUDENT\_GRADE` table. |
|
|
4796 |
|
- The grade of one student for one particular exam stored in the `STUDENT_GRADE` table. |
4790 |
4797 |
|
|
4791 |
4798 |
Unfortunately, this design turned out to be terrible. |
Unfortunately, this design turned out to be terrible. |
4792 |
4799 |
Describe at least one common and interesting situation where this model would fail to fulfill its purpose, and propose a way to correct the particular problem you identified. |
Describe at least one common and interesting situation where this model would fail to fulfill its purpose, and propose a way to correct the particular problem you identified. |
|
... |
... |
Problem (Reading the MOVIES database ER schema) +.#movie |
4801 |
4808 |
 |
 |
4802 |
4809 |
|
|
4803 |
4810 |
Assume that MOVIES is a populated database. |
Assume that MOVIES is a populated database. |
4804 |
|
ACTOR is used as a gender-netral term. |
|
|
4811 |
|
ACTOR is used as a gender-neutral term. |
4805 |
4812 |
Given the constraints shown in the ER schema, respond to the following statements with *True* or *False*. |
Given the constraints shown in the ER schema, respond to the following statements with *True* or *False*. |
4806 |
4813 |
Justify each answer. |
Justify each answer. |
4807 |
4814 |
|
|
|
... |
... |
Problem (Reading the MOVIES database ER schema) +.#movie |
4810 |
4817 |
#. Some actors could have done a lead role in multiple movies. |
#. Some actors could have done a lead role in multiple movies. |
4811 |
4818 |
#. A movie can have only a maximum of two lead actors. |
#. A movie can have only a maximum of two lead actors. |
4812 |
4819 |
#. Every director have to have been an actor in some movie. |
#. Every director have to have been an actor in some movie. |
4813 |
|
#. No producer has ever been an actor. |
|
|
4820 |
|
#. No producer has ever been an actor. |
4814 |
4821 |
#. A producer cannot be an actor in some other movie. |
#. A producer cannot be an actor in some other movie. |
4815 |
4822 |
#. There could be movies with more than a dozen actors. |
#. There could be movies with more than a dozen actors. |
4816 |
4823 |
#. Producers can be directors as well. |
#. Producers can be directors as well. |