Download presentation
Presentation is loading. Please wait.
1
Programming with data Lab 8
Wednesday, 5 December 2018 Stelios Sotiriadis Prof. Alessandro Provetti
2
Study the following Entity relationshp diagram
How to create an ER diagram: Create boxes for each entity Model the relationships between each by drawing lines to connect related entities. Identify relevant attributes within each entity. Review your model.
3
In class activity: Design a database (DB) system
Create small teams and work together to design a DB system You task is to design an ER diagram for an online book store. Identify at least 5 tables Create the relationships between the tables A yellow team meet with one blue team to discuss their findings
4
SQL Queries Class8-sql-exercise-1.txt
5
1 Create the following tables
6
1 Create the following tables
Create a table called department. Entities: DeptName varchar(24) not null primary key, Address varchar(24), City varchar(24) Create a table called employee. Entities: employeeID integer primary key, FirstName varchar(24) not null, Surname varchar(24) not null, Dept varchar(24) not null REFERENCES department(DeptName), Office integer, Salary Integer, City varchar(24)
7
2 Insert data (Class8-sql-exercise-1.txt)
INSERT ALL INTO department (DeptName, Address, City) VALUES ('Administration','Bond Street','London') INTO department (DeptName, Address, City) VALUES ('Production','Rue Victor Hugo','Toulouse') INTO department (DeptName, Address, City) VALUES ('Distribution','Pond Street','Brighton') INTO department (DeptName, Address, City) VALUES ('Planning','Bond Street','London') INTO department (DeptName, Address, City) VALUES ('Research','Sunset Street','San Jose') SELECT * FROM dual; INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (100,'Mary','Brown','Administration',10,45,'London') INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (101,'Charles','White','Production',20,36,'Toulouse') INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (102,'Gus','Green','Administration',20,40,'Toulouse') INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (103,'Jackson','Neri','Distribution',16,45,'Toulouse') INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (104,'Charles','Brown','Planning',14,80,'Toulouse') INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (105,'Laurence','Chen','Planning',7,73,'Toulouse') INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (106,'Pauline','Bradshaw','Administration',75,40,'Toulouse') INTO employee (employeeID, FirstName, Surname, Dept, Office, Salary, City) VALUES (107,'Alice','Jackson','Production',20,46,'Toulouse')
8
3 Run the following queries:
Find the salaries of employees named Brown. Find all the information relating to employees named Brown. Find the monthly salary of the employees named White. Find the names of the employees and the cities in which they work (Simple join query) Find the names of the employees and the cities in which they work (using an alias)
9
3 Run the following queries:
Find the first names and surnames of the employees who work in office number 20 of the Administration department Find the first names and surnames of the employees who work in either the Administration or the Production department. Find the first names of the employees named Brown who work in the Administration department or the Production department Find the employees with surnames that have ‘r’ as the second letter and end in ‘n’ Find the names of the employees and the cities in which they work.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.