Skip to content

Instantly share code, notes, and snippets.

@santiagocodes
Created May 23, 2019 14:21
Show Gist options
  • Save santiagocodes/0bdc9bc4517eef1cdaa9007cc1f5785b to your computer and use it in GitHub Desktop.
Save santiagocodes/0bdc9bc4517eef1cdaa9007cc1f5785b to your computer and use it in GitHub Desktop.
SQL03- Data handling
## Wizardry schools
Insert in the school table the following data...
mysql> INSERT INTO school (name, country, capacity) VALUES
-> ('Beauxbatons Academy of Magic', 'France', 550),
-> ('Castelobruxo', 'France', 380),
-> ('Durmstrang Institute', 'Norway', 570),
-> ('Hogwarts School of Witchcraft and Wizardry', 'United Kindom', 450),
-> ('Ilvermorny School of Witchcraft and Wizardry', 'USA', 300),
-> ('Koldovstoretz', 'Russia', 125),
-> ('Mahoutokoro School of Magic', 'Japan', 800),
-> ('Uagadou School of Magic', 'Uganda', 350);
Query OK, 8 rows affected (0.35 sec)
Records: 8 Duplicates: 0 Warnings: 0
1. “Durmstrang Institute” is actually in Sweden (Sweden), so modify its country.
mysql> UPDATE school
-> SET country='Sweden'
-> WHERE name='Durmstrang Institute';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
2. “Mahoutokoro School of Magic” should have its pupil capacity reduced to 700.
mysql> UPDATE school
-> SET capacity=700
-> WHERE name='Mahoutokoro School of Magic';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
3. Delete all the schools containing the word “Magic” (there are 3) in their titles in a single request.
The LIKE keyword may be of help to you.
mysql> DELETE FROM school
-> WHERE name LIKE '%magic%';
Query OK, 3 rows affected (0.02 sec)
4. Then, display via a SELECT request all the data in the school table and paste the result in the gist as well.
mysql> SELECT * FROM school;
+----+----------------------------------------------+----------+---------------+
| id | name | capacity | country |
+----+----------------------------------------------+----------+---------------+
| 2 | Castelobruxo | 380 | France |
| 3 | Durmstrang Institute | 570 | Sweden |
| 4 | Hogwarts School of Witchcraft and Wizardry | 450 | United Kindom |
| 5 | Ilvermorny School of Witchcraft and Wizardry | 300 | USA |
| 6 | Koldovstoretz | 125 | Russia |
+----+----------------------------------------------+----------+---------------+
5 rows in set (0.00 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment