File notes/00_sum.md changed (mode: 100644) (index b1c63c6..d6dc62b) |
... |
... |
On top of the [references](references) and of the "resources" listed at the begi |
114 |
114 |
- Make better makefile (compile images in latex, clean up, etc.). |
- Make better makefile (compile images in latex, clean up, etc.). |
115 |
115 |
- Check that order of exercises / problems match introduction in lecture. |
- Check that order of exercises / problems match introduction in lecture. |
116 |
116 |
- Check that solution of exercises numbering match exercise numbering. |
- Check that solution of exercises numbering match exercise numbering. |
|
117 |
|
- numbering of Question in exercises is faulty: 1 numbering for all exercises! |
117 |
118 |
|
|
118 |
119 |
# Introduction |
# Introduction |
119 |
120 |
|
|
|
... |
... |
GRANT ALL PRIVILEGES ON `HW\_%` . * TO |
2024 |
2025 |
'testuser'@'localhost'; |
'testuser'@'localhost'; |
2025 |
2026 |
~~~ |
~~~ |
2026 |
2027 |
|
|
2027 |
|
Be careful: backticks (`` ` ``) are surrounding `HW\_` whereas single quotes (`'`) are surrounding `testuser` and `localhost`. |
|
|
2028 |
|
Be careful: backticks (`` ` ``) are surrounding `HW\_%` whereas single quotes (`'`) are surrounding `testuser` and `localhost`. |
2028 |
2029 |
|
|
2029 |
2030 |
And then we quit the DBMS, using |
And then we quit the DBMS, using |
2030 |
2031 |
|
|
|
... |
... |
Now, let us create our first schema, our first table, populate it with data, and |
2077 |
2078 |
We first create the schema (or database), `HW_FirstTest`: |
We first create the schema (or database), `HW_FirstTest`: |
2078 |
2079 |
|
|
2079 |
2080 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
2080 |
|
CREATE DATABASE HW_FirstTest; |
|
|
2081 |
|
CREATE DATABASE HW_FirstTest; -- Or CREATE SCHEMA HW_FirstTest; |
2081 |
2082 |
~~~ |
~~~ |
2082 |
2083 |
|
|
2083 |
2084 |
Let us make sure that we created it: |
Let us make sure that we created it: |
|
... |
... |
And see what it contains now: |
2098 |
2099 |
SHOW TABLES; |
SHOW TABLES; |
2099 |
2100 |
~~~ |
~~~ |
2100 |
2101 |
|
|
2101 |
|
We now create a table called `TableTest`: |
|
|
2102 |
|
We now create a table called `TableTest`, wtih two integer attributes called `Attribute1` and `Attribute2`: |
2102 |
2103 |
|
|
2103 |
2104 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
2104 |
2105 |
CREATE TABLE TableTest (Attribute1 INT, Attribute2 INT); |
CREATE TABLE TableTest (Attribute1 INT, Attribute2 INT); |
2105 |
2106 |
~~~ |
~~~ |
2106 |
2107 |
|
|
2107 |
|
And can make sure that it was indeed created: |
|
|
2108 |
|
And can make sure that the table was indeed created: |
2108 |
2109 |
|
|
2109 |
2110 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
2110 |
2111 |
SHOW TABLES; |
SHOW TABLES; |
|
... |
... |
Those are the commands implemented in the DBMS you are actually using. |
2207 |
2208 |
Since there are small variations from one implementation to the other, it's better to take one of this link as a reference in the future. |
Since there are small variations from one implementation to the other, it's better to take one of this link as a reference in the future. |
2208 |
2209 |
|
|
2209 |
2210 |
|
|
2210 |
|
Problem (SQL -- Creating and using a simple table) +.#address |
|
|
2211 |
|
Problem (Creating and using a simple table in SQL) +.#address |
2211 |
2212 |
|
|
2212 |
|
Question -.# |
|
|
2213 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2213 |
2214 |
~ Log in as `testuser`, create a database named `HW_Address`, use it, and create two tables: |
~ Log in as `testuser`, create a database named `HW_Address`, use it, and create two tables: |
2214 |
2215 |
|
|
2215 |
2216 |
~~~{.sqlmysql .numberLines} |
~~~{.sqlmysql .numberLines} |
|
... |
... |
CREATE TABLE ADDRESS( |
2228 |
2229 |
); |
); |
2229 |
2230 |
~~~ |
~~~ |
2230 |
2231 |
|
|
2231 |
|
Question -.# |
|
|
2232 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2232 |
2233 |
~ Observe the output produced by the command |
~ Observe the output produced by the command |
2233 |
2234 |
|
|
2234 |
2235 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
2235 |
2236 |
DESC ADDRESS; |
DESC ADDRESS; |
2236 |
|
~~ |
|
2237 |
|
|
|
|
2237 |
|
~~~ |
2238 |
2238 |
|
|
2239 |
|
Question -.# |
|
|
2239 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2240 |
2240 |
~ Add a foreign key to the `ADDRESS` table, using |
~ Add a foreign key to the `ADDRESS` table, using |
2241 |
2241 |
|
|
2242 |
2242 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
|
... |
... |
Question -.# |
2251 |
2251 |
DESC ADDRESS; |
DESC ADDRESS; |
2252 |
2252 |
~~~ |
~~~ |
2253 |
2253 |
|
|
2254 |
|
Is it what you would have expected? How informative is it? Can you think of a command that would output more detailled information? |
|
|
2254 |
|
Is it what you would have expected? How informative is it? Can you think of a command that would output more detailled information, including a reference to the existence of the foreign key? |
2255 |
2255 |
|
|
2256 |
|
Question -.# |
|
2257 |
|
~ Draw the relations corresponding to that database, including the primary, as well as foreign, keys. |
|
|
2256 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
|
2257 |
|
~ Draw the relational model corresponding to that database, including the primary, as well as foreign, keys. |
2258 |
2258 |
|
|
2259 |
|
Question -.# |
|
|
2259 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2260 |
2260 |
~ Add some data in the `NAME` table: |
~ Add some data in the `NAME` table: |
2261 |
2261 |
|
|
2262 |
2262 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
|
... |
... |
Question -.# |
2268 |
2268 |
What command can you use to display this infomation back? |
What command can you use to display this infomation back? |
2269 |
2269 |
Do you notice anything regarding the values we entered for the `Id` attribute? |
Do you notice anything regarding the values we entered for the `Id` attribute? |
2270 |
2270 |
|
|
2271 |
|
Question -.# |
|
|
2271 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2272 |
2272 |
~ Add some data into the `ADDRESS` table: |
~ Add some data into the `ADDRESS` table: |
2273 |
2273 |
|
|
2274 |
2274 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
|
... |
... |
Question -.# |
2281 |
2281 |
|
|
2282 |
2282 |
What difference do you note with the insertions we made in the `NAME` table. Which syntax seem more easy to you? |
What difference do you note with the insertions we made in the `NAME` table. Which syntax seem more easy to you? |
2283 |
2283 |
|
|
2284 |
|
Question -.# |
|
|
2284 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2285 |
2285 |
~ Write a `SELECT` statement that returns the `Id` number of the person whose first name is "Samantha". |
~ Write a `SELECT` statement that returns the `Id` number of the person whose first name is "Samantha". |
2286 |
2286 |
|
|
2287 |
|
Question -.# |
|
|
2287 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2288 |
2288 |
~ Write a statement that violate the entity integrity constraint. What is the error message returned? |
~ Write a statement that violate the entity integrity constraint. What is the error message returned? |
2289 |
2289 |
|
|
2290 |
|
Question -.# |
|
|
2290 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2291 |
2291 |
~ Execute an `UPDATE` statement that violate the referential integrity constraint. What is the error message returned? |
~ Execute an `UPDATE` statement that violate the referential integrity constraint. What is the error message returned? |
2292 |
2292 |
|
|
2293 |
|
Question -.# |
|
|
2293 |
|
[Pb %s.%c](#problem:address) -- Question -.# |
2294 |
2294 |
~ Write a statement that violate another kind of constraint. Explain what constraint you are violating, and explain the error message. |
~ Write a statement that violate another kind of constraint. Explain what constraint you are violating, and explain the error message. |
2295 |
2295 |
|
|
2296 |
2296 |
|
|
2297 |
|
Problem (Repetiting tuples in MySQL) +.-.#repetition |
|
|
2297 |
|
Problem (Duplicate rows in SQL) +.#repetition |
2298 |
2298 |
|
|
2299 |
|
Log in as `testuser` and create a database `HW_2Q4`. Tell MySQL that you want to use that database, and create a table (I will assume you named it `EXAMPLE` in the following, but you are free to name it the way you want) with at least two attributes that have different data types. Don't declare a primary key yet. Answer the following: |
|
|
2299 |
|
Log in as `testuser` and create a database `HW_REPETITION`. |
|
2300 |
|
Create in that database a table (I will assume you named it `EXAMPLE` in the following, but you are free to name it the way you want) with at least two attributes that have different data types. Don't declare a primary key yet. Answer the following: |
2300 |
2301 |
|
|
2301 |
|
#. Add a tuple to your table using |
|
|
2302 |
|
[Pb %s.%c](#problem:repetition) -- Question -.# |
|
2303 |
|
~ Add a tuple to your table using |
2302 |
2304 |
|
|
2303 |
2305 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
2304 |
2306 |
INSERT INTO EXAMPLE VALUES(X, Y); |
INSERT INTO EXAMPLE VALUES(X, Y); |
|
... |
... |
Log in as `testuser` and create a database `HW_2Q4`. Tell MySQL that you want to |
2313 |
2315 |
|
|
2314 |
2316 |
to observe what is stored in this table.) |
to observe what is stored in this table.) |
2315 |
2317 |
|
|
2316 |
|
#. Alter your table to add a primary key, using |
|
|
2318 |
|
[Pb %s.%c](#problem:repetition) -- Question -.# |
|
2319 |
|
~ Alter your table to add a primary key, using |
2317 |
2320 |
|
|
2318 |
2321 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
2319 |
2322 |
ALTER TABLE EXAMPLE ADD PRIMARY KEY (Attribute); |
ALTER TABLE EXAMPLE ADD PRIMARY KEY (Attribute); |
|
... |
... |
Log in as `testuser` and create a database `HW_2Q4`. Tell MySQL that you want to |
2321 |
2324 |
|
|
2322 |
2325 |
where `Attribute` is the name of the attribute you want to be a primary key. What do you observe? |
where `Attribute` is the name of the attribute you want to be a primary key. What do you observe? |
2323 |
2326 |
|
|
2324 |
|
#. Empty your table using |
|
|
2327 |
|
[Pb %s.%c](#problem:repetition) -- Question -.# |
|
2328 |
|
~ Empty your table using |
2325 |
2329 |
|
|
2326 |
2330 |
~~~{.sqlmysql} |
~~~{.sqlmysql} |
2327 |
2331 |
DELETE FROM EXAMPLE; |
DELETE FROM EXAMPLE; |
|
... |
... |
Log in as `testuser` and create a database `HW_2Q4`. Tell MySQL that you want to |
2329 |
2333 |
|
|
2330 |
2334 |
and alter your table to add a primary key, using the command we gave at the previous step. What do you observe? |
and alter your table to add a primary key, using the command we gave at the previous step. What do you observe? |
2331 |
2335 |
|
|
2332 |
|
#. Try to add the same tuple twice. What do you observe? |
|
2333 |
|
|
|
|
2336 |
|
[Pb %s.%c](#problem:repetition) -- Question -.# |
|
2337 |
|
~ Try to add the same tuple twice. What do you observe? |
2334 |
2338 |
|
|
2335 |
2339 |
|
|
2336 |
2340 |
### Prof Revisited |
### Prof Revisited |
File notes/temp.md added (mode: 100644) (index 0000000..cee6465) |
|
1 |
|
--- |
|
2 |
|
documentclass: scrreprt |
|
3 |
|
papersize: letter |
|
4 |
|
bibliography: [ bib/bib.bib ] |
|
5 |
|
link-citations: true |
|
6 |
|
title: CSCI 3410 - Database Systems |
|
7 |
|
subtitle: Lecture Notes (Draft) |
|
8 |
|
author: Clément Aubert |
|
9 |
|
institute: Augusta University |
|
10 |
|
dir: ltr |
|
11 |
|
lang: en |
|
12 |
|
numbersections: true |
|
13 |
|
mainfont: Linux Libertine O |
|
14 |
|
copyright: TEST |
|
15 |
|
keywords: |
|
16 |
|
- Computer Science |
|
17 |
|
- Database |
|
18 |
|
- MySQL programming |
|
19 |
|
header-includes: |
|
20 |
|
- \usepackage{latex/packages} |
|
21 |
|
--- |
|
22 |
|
|
|
23 |
|
<!-- |
|
24 |
|
pandoc temp.md --pdf-engine=xelatex --toc --filter pandoc-numbering --filter pandoc-citeproc --top-level-division=chapter -M date="`date "+%B %e, %Y"`" -o temp.pdf |
|
25 |
|
pandoc temp.md --pdf-engine=xelatex --toc --filter pandoc-numbering --filter pandoc-citeproc --top-level-division=chapter -M date="`date "+%B %e, %Y"`" -s -o temp.html |
|
26 |
|
--> |
|
27 |
|
|
|
28 |
|
|
|
29 |
|
# Bla |
|
30 |
|
|
|
31 |
|
## Problem |
|
32 |
|
|
|
33 |
|
Problem (Creating and using a simple table in SQL) +.#address |
|
34 |
|
|
|
35 |
|
Question -.# |
|
36 |
|
~ Log in as `testuser`, create a database named `HW_Address`, use it, and create two tables: |
|
37 |
|
|
|
38 |
|
~~~{.sqlmysql .numberLines} |
|
39 |
|
CREATE TABLE NAME( |
|
40 |
|
FName VARCHAR(15), |
|
41 |
|
LName VARCHAR(15), |
|
42 |
|
Id INT, |
|
43 |
|
PRIMARY KEY(Id) |
|
44 |
|
); |
|
45 |
|
|
|
46 |
|
CREATE TABLE ADDRESS( |
|
47 |
|
StreetName VARCHAR(15), |
|
48 |
|
Number INT, |
|
49 |
|
Habitants INT, |
|
50 |
|
PRIMARY KEY(StreetName, Number) |
|
51 |
|
); |
|
52 |
|
~~~ |
|
53 |
|
|
|
54 |
|
Question -.# |
|
55 |
|
~ Observe the output produced by the command |
|
56 |
|
|
|
57 |
|
~~~{.sqlmysql} |
|
58 |
|
DESC ADDRESS; |
|
59 |
|
~~~ |
|
60 |
|
|
|
61 |
|
Question -.# |
|
62 |
|
~ Add a foreign key to the `ADDRESS` table, using |
|
63 |
|
|
|
64 |
|
~~~{.sqlmysql} |
|
65 |
|
ALTER TABLE ADDRESS |
|
66 |
|
ADD FOREIGN KEY (Habitants) |
|
67 |
|
REFERENCES NAME(Id); |
|
68 |
|
~~~ |
|
69 |
|
|
|
70 |
|
And observe the new output produced by the command |
|
71 |
|
|
|
72 |
|
~~~{.sqlmysql} |
|
73 |
|
DESC ADDRESS; |
|
74 |
|
~~~ |
|
75 |
|
|
|
76 |
|
Is it what you would have expected? How informative is it? Can you think of a command that would output more detailled information, including a reference to the existence of the foreign key? |
|
77 |
|
|
|
78 |
|
Question -.# |
|
79 |
|
~ Draw the relational model corresponding to that database, including the primary, as well as foreign, keys. |
|
80 |
|
|
|
81 |
|
Question -.# |
|
82 |
|
~ Add some data in the `NAME` table: |
|
83 |
|
|
|
84 |
|
~~~{.sqlmysql} |
|
85 |
|
INSERT INTO NAME VALUES ('Barbara', 'Liskov', 003); |
|
86 |
|
INSERT INTO NAME VALUES ('Tuong Lu', 'Kim', 004); |
|
87 |
|
INSERT INTO NAME VALUES ('Samantha', NULL, 080); |
|
88 |
|
~~~ |
|
89 |
|
|
|
90 |
|
What command can you use to display this infomation back? |
|
91 |
|
Do you notice anything regarding the values we entered for the `Id` attribute? |
|
92 |
|
|
|
93 |
|
Question -.# |
|
94 |
|
~ Add some data into the `ADDRESS` table: |
|
95 |
|
|
|
96 |
|
~~~{.sqlmysql} |
|
97 |
|
INSERT INTO ADDRESS |
|
98 |
|
VALUES |
|
99 |
|
('Armstrong Drive', 10019, 003), |
|
100 |
|
('North Broad St.', 23, 004), |
|
101 |
|
('Robert Lane', 120, NULL); |
|
102 |
|
~~~ |
|
103 |
|
|
|
104 |
|
What difference do you note with the insertions we made in the `NAME` table. Which syntax seem more easy to you? |
|
105 |
|
|
|
106 |
|
Question -.# |
|
107 |
|
~ Write a `SELECT` statement that returns the `Id` number of the person whose first name is "Samantha". |
|
108 |
|
|
|
109 |
|
Question -.# |
|
110 |
|
~ Write a statement that violate the entity integrity constraint. What is the error message returned? |
|
111 |
|
|
|
112 |
|
Question -.# |
|
113 |
|
~ Execute an `UPDATE` statement that violate the referential integrity constraint. What is the error message returned? |
|
114 |
|
|
|
115 |
|
Question -.# |
|
116 |
|
~ Write a statement that violate another kind of constraint. Explain what constraint you are violating, and explain the error message. |
|
117 |
|
|
|
118 |
|
|
|
119 |
|
Problem (Duplicate rows in SQL) +.#repetition |
|
120 |
|
|
|
121 |
|
Log in as `testuser` and create a database `HW_REPETITION`. |
|
122 |
|
Create in that database a table (I will assume you named it `EXAMPLE` in the following, but you are free to name it the way you want) with at least two attributes that have different data types. Don't declare a primary key yet. Answer the following: |
|
123 |
|
|
|
124 |
|
@problem:repetition -- Question -.# |
|
125 |
|
~ Add a tuple to your table using |
|
126 |
|
|
|
127 |
|
|
|
128 |
|
[Pb T %T t %t D %D d %d s %s g %g c %c p %p n %n \# #](#problem:repetition "caption") -- Question -.# |
|
129 |
|
~ Add a tuple to your table using |
|
130 |
|
|
|
131 |
|
|
|
132 |
|
[Pb T %T t %t D %D d %d s %s g %g c %c p %p n %n \# #](#problem:repetition "caption") -- Question -.# |
|
133 |
|
~ Add a tuple to your table using |
|
134 |
|
|
|
135 |
|
|
|
136 |
|
[Pb %s.%c ](#problem:repetition "caption") -- Question -.# |
|
137 |
|
~ Add a tuple to your table using |
|
138 |
|
|
|
139 |
|
|
|
140 |
|
[Pb %s.%c](#problem:repetition "caption") -- Question -.# |
|
141 |
|
~ Add a tuple to your table using |
|
142 |
|
|
|
143 |
|
[Problem %g](#problem:repetition) -- Question -.# |
|
144 |
|
|
|
145 |
|
1.2 |