Professional Documents
Culture Documents
Workshop
Hands-On
Workshop: RDBMS
Design
Goals
To understand and apply relational
database design techniques.
Tools
This hands-on workshop will use a free
online database where all the exercises
will be carried out. Students can gain
access to it through their web browsers
at https://sqliteonline.com/ choosing
PostgreSQL on the left pane and clicking
on ‘Click to connect’. This will open a
new session on a PostgreSQL database
with an empty instance.
Introduction
https://docs.google.com/document/d/e/2PACX-1vSJg0I4U5Ej_zf2ZstpKA4ASuyr89yNw9PFxpmtqh-par6jYzoaQBF-kOB_SrkarZgF8whfJamUAmEo/pub 1/6
13/11/2020 APSV-20-21-TEMA-10-RDBMSDesign-EN
https://docs.google.com/document/d/e/2PACX-1vSJg0I4U5Ej_zf2ZstpKA4ASuyr89yNw9PFxpmtqh-par6jYzoaQBF-kOB_SrkarZgF8whfJamUAmEo/pub 2/6
13/11/2020 APSV-20-21-TEMA-10-RDBMSDesign-EN
Acronym VARCHAR(8) PRIMARY
KEY, Actualizado automáticamente cada 5
APSV-20-21-TEMA-10-RDBMSDesign-EN minutos
Name VARCHAR(255) NOT NULL
UNIQUE
)
Now, let’s check that the DBMS
enforces the constraints we have just
set. Connect to a PostgreSQL database
at the SQL editor
(https://sqliteonline.com/), create the
table using the statement above, and
then try the following commands and
explain why they worked (or not)[1].
Note: Trying to copy text from a PDF
and pasting it into the browser may
cause the single and double quotes to
be misunderstood by the browser (you
may get an 42601 syntax error at or
near "..."). To solve this issue you
should type the quotes or the whole
statement on your own in your SQL
editor.
INSERT INTO GROUPS(acronym,
name)
VALUES(‘ING’, ‘Internet de Nueva
Generación’)
INSERT INTO GROUPS(acronym,
name)
VALUES(“TooLongAcronym”, “Another
group”)
INSERT INTO GROUPS(acronym,
name)
VALUES(‘ING’, ‘Another group’)
INSERT INTO GROUPS(name)
VALUES(‘Yet another group’)
https://docs.google.com/document/d/e/2PACX-1vSJg0I4U5Ej_zf2ZstpKA4ASuyr89yNw9PFxpmtqh-par6jYzoaQBF-kOB_SrkarZgF8whfJamUAmEo/pub 4/6
13/11/2020 APSV-20-21-TEMA-10-RDBMSDesign-EN
e. Email can’t be NULL
and must be UNIQUE. Actualizado automáticamente cada 5
APSV-20-21-TEMA-10-RDBMSDesign-EN minutos
f. The research group
(rgroup) can’t be null,
and it’s a FK.
6. Once we have all the table
details we can create the code
to instantiate it:
CREATE TABLE researchers(
Id SERIAL PRIMARY KEY,
Name VARCHAR(255) NOT
NULL,
ORCID VARCHAR(16) UNIQUE,
Office VARCHAR(5) NOT NULL,
Email VARCHAR(255) NOT
NULL UNIQUE,
rGroup VARCHAR(8) NOT
NULL,
CONSTRAINT fk_groups
FOREIGN KEY(rGroup)
REFERENCES
Groups(Acronym)
)
Now, let’s check that the DBMS
enforces the constraints we have just
set. Try the following commands in
your SQL editor, and explain why they
worked (or not).
INSERT INTO researchers(name, office,
ORCID, email, rgroup)
VALUES(‘Jose’, ‘B204’,
'0001000200030004',
‘jm.delalamo@upm.es’, 'ING')
INSERT INTO researchers(name, office,
ORCID, email)
VALUES(‘Juan’, ‘B201’,
'0002000200030005', ‘juan@upm.es’)
Now, following the same process create
the Projects table, taking into account
that:
a. Each entity always maps to a
table, including all the entity
attributes as table columns.
b. Each many-to-many
relationship maps to a
new table: The ‘participates’
relationship maps to the
Participants table including
Project (Foreign Key from
Projects) and Researcher (FK
from Researchers) as columns.
The student must carry out the
following tasks in pairs:
https://docs.google.com/document/d/e/2PACX-1vSJg0I4U5Ej_zf2ZstpKA4ASuyr89yNw9PFxpmtqh-par6jYzoaQBF-kOB_SrkarZgF8whfJamUAmEo/pub 6/6