Uploaded by tiaojoelle

exercises2 - Copy

advertisement
LIACS ·
6)
SQLite introduction & ER to SQL
23.02.24
This exercise covers basic SQL statements that we will use throughout the course. The goal is to create a simple database system
that stores information about cars and their owners. Let us use
www.sqliteonline.com as an environment for this exercise.
a. Use the CREATE TABLE statement to define a new table that stores
information about cars. Record the license plate, colour and brand
of each car. Which would you use as the identifying attribute?
b. Use the INSERT statement to populate the new table with 5 cars.
c. Use the SELECT statement to display (i) the entire table, and (ii)
only select cars with a specific colour, e.g., blue.
d. Let us record information about the owners of the cars. CREATE
a table containing social security number, name and email address.
Identify a primary key. INSERT a few persons into the new table
and DELETE one row.
e. In order to join the tables, they need a common attribute. If one
person can own multiple cars, but each car can only have one owner,
in which table should the common attribute be added? Use ALTER
TABLE to add the column.
f. The new column is empty, use UPDATE to record an owner for each
car. Make sure at least one owner has multiple cars.
g. Use SELECT and join the tables to find the colours of the cars that
are owned by a specific person.
h. Use ALTER TABLE to remove the column that you previously added.
i. Change the database so that the relation between cars and owners
is many-to-many, i.e. a car can also be owned by multiple owners.
How would you now query the database to find the colours of the
cars owned by a specific person?
7) [Exercise 3.12, DBMS] Consider the scenario from exercise 1, where you
designed an ER diagram. Write SQL statements to create the corresponding relations and capture as many of the constraints as possible.
If you cannot capture some constraints, explain why.
8) [Exercise 3.14, DBMS] The same question as in the exercise 7 but now considering the ER diagram of exercise 3.
9) [Exercise 3.16, DBMS] The same question as in the exercise 7 but now considering the ER diagram of exercise 5.
Download