You are on page 1of 7

BD05

Exercise 1

​ ● Insert a new record in the CITY table using the graphical tool offered
by Mysql Workbench. The data must be the following:
id: 7 name: Inca

First we double click the last column to add information.

Then we click the apply button at the bottom right corner on the result grid.

And we should get a pop-up that shows us the query it ran and that the information
has been successfully added to the DB.
● Insert a new record in the SCHOOL table using the graphical tool offered by
Mysql Workbench. The data must be the following:
id: 9
name: Pau Casesnoves manager: Antoni Garau city_id: 7
You must provide screenshots of the data insertion process and the moment
before applying the changes. Think about describing the captures.

Same procedure as before, we input the data on the table and click apply:

We should get this query, once we hit apply the data will be in the DB.
Exercise 2

Insert more records into the STUDENT table using SQL statements. In the
delivery of the task you must copy the sentences that you have used. The data
must be the following:
The data that does not appear should not be used in the statements.

INSERT INTO `OLYMPICS`. `STUDENT` (`school_id`, `id`, `name`, `birthdate`,


`gender`)

VALUES

('9', '1', 'Macià', '2001-10-25', 'M') ,

('9', '2', 'Nadal', NULL , 'M'),

('9', '3', 'Julia', '2001-12-23', 'F'),

('1', '14', 'Montse', NULL, NULL);


Exercise 3

Modify some student names. Use the graphical tool to do this, submitting with the
task screenshots showing all the changes you have made. The names that you must
change are, student table:

First we change the data by double clicking the row we want to modify.

Then we’ll get the script, we hit apply again, and the changes will be made.
Exercise 4

Modify the SCHOOL record Named "Drago", using SQL statements, and
change its name to "Dracaena draco" and the manager to "Francisca". Do it
using a single SQL statement and copy it for the delivery of the task.

UPDATE `OLYMPICS`. `SCHOOL`

SET `name` = 'Dracaena draco', `manager` = 'Francisca'

WHERE `id` = '8';

Exercise 5

Capitalize the names of students who are female. Do it using a single SQL
statement and copy it for the delivery of the task.
https://www.w3schools.com/mysql/mysql_ref_functions.asp

SELECT UPPER(`name`) AS `name`

FROM `OLYMPICS`. `STUDENT`

WHERE `gender` = 'f';

Exercise 6

Set the first of January, 2000 as birthdate for those students with a null value
in this field. Do it using a single SQL statement and copy it for the delivery of
the task.

UPDATE `OLYMPICS`. `STUDENT`

SET `birthdate` = '2000-01-01'

WHERE `birthdate` IS NULL ;


Exercise 7

Remove from the STUDENT table, those students with a null value in gender
field. Do it using only one SQL statement and copy it for the delivery of the
task.

DELETE FROM `OLYMPICS` . `STUDENT`

WHERE `gender` IS NULL;

Exercise 8

Eliminate those students who are not participants in any modality of the
Olympics. Do it using only one SQL statement and copy it for the delivery of
the task.

DELETE `STUDENT`

FROM `OLYMPICS`.`STUDENT`

LEFT JOIN `OLYMPICS` . `PARTICIPANT`

ON `school_id` = `student_school_id` AND `id` = `student_id`

WHERE `student_id` IS NULL

Exercise 9

Students from school id 9 (Pau Casesnoves) will participate in the Olympics


with the modality 3 (Information Technology). Insert them into PARTICIPANT
table. Do it using only one SQL statement and copy it for the delivery of the
task. https://www.w3schools.com/mysql/mysql_insert_into_select.asp

INSERT INTO `PARTICIPANT` (`student_school_id`, `student_id`, `modality_id`)

SELECT s.`school_id`, s.`id` , m.`id` FROM `STUDENT` AS s, `MODALITY` AS m

WHERE s.`school_id` = '9';


Exercise 10

Change the name of students that contain the surname “Fernández” for the
same name joined to his dorsal (composed by school id and student id). For
example, "Castilla Fernandez, Luis" will change to " Castilla Fernandez, Luis -
603" because his school id is 6 and his student id is 03. Do it using only one
SQL statement and copy it for the delivery of the task.

UPDATE `OLYMPICS`. `STUDENT`

SET `name` = CONCAT( `name` ,`school_id` ,`id`)

WHERE `name` LIKE '%fernandez%';

You might also like