MySQL: Difference between revisions

From 22112
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 8: Line 8:
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=9162c944-634a-4c14-b784-af270125d681 Using SQL language to create tables, manipulate data and retrieve data.]<br>
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=9162c944-634a-4c14-b784-af270125d681 Using SQL language to create tables, manipulate data and retrieve data.]<br>
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=3158d3b6-b07a-4f3e-9211-af270125af81 Functions in SQL (aggregate, string, math, etc), loading files into tables, vice versa]<br>
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=3158d3b6-b07a-4f3e-9211-af270125af81 Functions in SQL (aggregate, string, math, etc), loading files into tables, vice versa]<br>
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/HPCLife12-MySQL.ppt MySQL]<br>
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_02-MySQL.ppt MySQL]<br>
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a3d3779d-2d3b-4fa8-83f6-af170071d48b Exercises]
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a3d3779d-2d3b-4fa8-83f6-af170071d48b Exercises]


Line 16: Line 16:
'''1)'''
'''1)'''
In /home/projects/pr_course there are 3 files: persons.csv, marriage.csv and disease.csv. That is data that corresponds to the database design exercise 2 last week.
In /home/projects/pr_course there are 3 files: persons.csv, marriage.csv and disease.csv. That is data that corresponds to the database design exercise 2 last week.
Your task is to investigate the data, so you know how it looks. Then you must create a database on '''pupil1''' MySQL database system with the ’mysql’ command. <span style="color: red;">You have the privilege to create a database with your DTU username, (the name of the databse is your username)</span>, nothing else. In that database, create tables that match the 3 files. Load the files into the tables.
Your task is to investigate the data, so you know how it looks. Then you must create a database on '''pupil1''' MySQL database system with the ’mysql’ command. <span style="color: red;">You have the privilege to create a database with your DTU username, (the name of the database is your username)</span>, nothing else. In that database, create tables that match the 3 files. Load the files into the tables.


  Table overview:
  Table overview:
Line 30: Line 30:
# Who do not have a father ?
# Who do not have a father ?
# How many do not have a mother?
# How many do not have a mother?
# How many cases of cancer - any type?
# How many cases of cancer - any type? You get to decide if a tumor also means cancer.
# How many persons had cancer – any type?
# How many persons had cancer – any type?
# Who are or have been married to someone named ’Finn’?
# Who are or have been married to someone named ’Finn’ (male name)?
# Create 2 imaginary persons. Marry them to each other. Make them have a kid. Give the kid a broken nose. Insert all this info in the database.
# Create 2 imaginary persons. Marry them to each other. Make them have a kid. Give the kid a broken nose. Insert all this info in the database.
# Delete everyone with the last name ’Rapacki’. Make sure that database is consistent afterwards, like there is no marriages to non-existing persons or references to non-existing parents.
# Delete everyone with the last name ’Rapacki’. Make sure that database is consistent afterwards, like there is no marriages to non-existing persons or references to non-existing parents.


The solutions to be handed in are the SQL statements, that solves the problems.
The solutions to be handed in are the SQL statements, that solves the problems.

Latest revision as of 07:00, 13 September 2024

Previous: Databases Next: Coding against databases

Material for the lesson

Note: The powerpoint has been updated with transactions, but not the video.
Video: Creating databases, data types
Video: Using SQL language to create tables, manipulate data and retrieve data.
Video: Functions in SQL (aggregate, string, math, etc), loading files into tables, vice versa
Powerpoint: MySQL
Video: Exercises

Exercises

1) In /home/projects/pr_course there are 3 files: persons.csv, marriage.csv and disease.csv. That is data that corresponds to the database design exercise 2 last week. Your task is to investigate the data, so you know how it looks. Then you must create a database on pupil1 MySQL database system with the ’mysql’ command. You have the privilege to create a database with your DTU username, (the name of the database is your username), nothing else. In that database, create tables that match the 3 files. Load the files into the tables.

Table overview:
persons.csv
   cpr, first name, last name, height, weight, biological mother, biological father
marriage.csv
   male cpr, female cpr, start of marriage, end of marriage
disease.csv
   cpr, name of disease, date of discovery

2) Use the SQL language to answer some questions about the data or manipulate it in some ways.

  1. Who do not have a father ?
  2. How many do not have a mother?
  3. How many cases of cancer - any type? You get to decide if a tumor also means cancer.
  4. How many persons had cancer – any type?
  5. Who are or have been married to someone named ’Finn’ (male name)?
  6. Create 2 imaginary persons. Marry them to each other. Make them have a kid. Give the kid a broken nose. Insert all this info in the database.
  7. Delete everyone with the last name ’Rapacki’. Make sure that database is consistent afterwards, like there is no marriages to non-existing persons or references to non-existing parents.

The solutions to be handed in are the SQL statements, that solves the problems.