0% found this document useful (0 votes)
25 views

DB Exercise 2 SQL 1

This document contains instructions for exercises involving SQL queries on a university database. It asks students to write SQL queries to retrieve information like the highest instructor salary, course titles by department and credits, student IDs for courses taught by a specific instructor, section enrollments by term, and instructors earning the highest salary. It also asks students to write SQL DDL for tables in a university schema and a case-insensitive query using the LOWER function. Additional questions involve Cartesian products, and converting relational algebra queries to SQL.

Uploaded by

giaphuc2004hg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

DB Exercise 2 SQL 1

This document contains instructions for exercises involving SQL queries on a university database. It asks students to write SQL queries to retrieve information like the highest instructor salary, course titles by department and credits, student IDs for courses taught by a specific instructor, section enrollments by term, and instructors earning the highest salary. It also asks students to write SQL DDL for tables in a university schema and a case-insensitive query using the LOWER function. Additional questions involve Cartesian products, and converting relational algebra queries to SQL.

Uploaded by

giaphuc2004hg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data and Web Science Group

Prof. Dr. Heiko Paulheim


B6,26 – B1.16
68159 Mannheim

Database Technology– FSS 2018


Exercise 2: SQL Part 1
2.1. SQL queries using university database
1. Start the XAMPP Control Panel and start MySQL/MariaDB and Apache
2. Open your Browser and browse to http://localhost/phpmyadmin
3. Click on the SQL tab and formulate SQL queries (using the university database) for the
following tasks:
a. Find the highest salary of any instructor.
b. Find the titles of courses in the Comp. Sci. department that have 3 credits.
c. Find the IDs of all students who were taught by an instructor named Einstein; make
sure there are no duplicates in the result.
d. Find the enrollment of each section that was offered in Spring 2009.
e. Find all instructors earning the highest salary (there may be more than one with the
same salary).
f. Find the maximum enrollment, across all sections, in Spring 2009.
g. Find the sections that had the maximum enrollment in Spring 2009.
2.2. SQL DDL using university schema
Write SQL DDL for the following tables in the university schema. Make any reasonable assumptions
about data types, and be sure to declare primary and foreign keys.

a. department
b. course
c. instructor
d. time_slot

2.3. SQL Like


The SQL “like” operator is case sensitive, but the lower() function on strings can be used to perform
case insensitive matching. To show how, write a query that finds departments whose names contain
the string “sci” as a substring, regardless of the case.

2.4. Cartesian Product


Consider the SQL query

SELECT p.a1
FROM p, r1, r2
WHERE p.a1 = r1.a1 or p.a1 = r2.a1

Under what conditions does the preceding query select values of p.a1 that are either in r1 or in r2?
Examine carefully the cases where one of r1 or r2 may be empty.

2.5. Relational algebra


Consider the following relational database. Give an expression in SQL for each of the queries.
employee (employee_name, street, city)
works (employee_name, company_name, salary)
company (company_name, city)
manages (employee_name, manager_name)

a. Find the names and cities of residence of all employees who work for First Bank Corporation.
b. Find the names, street addresses, and cities of residence of all employees who work for First
Bank Corporation and earn more than $10,000.
c. Assume that the companies may be located in several cities. Find all companies located in
every city in which Small Bank Corporation is located.
d. Find the company that has the most employees.
e. Find those companies whose employees earn a higher salary, on average, than the average
salary at First Bank Corporation.
f. Find all employees in the database who do not work for First Bank Corporation.
g. Find all employees in the database who earn more than each employee of Small Bank
Corporation.

You might also like