Database Worksheet 1-1
Database Worksheet 1-1
Worksheet #1
Topics covered:
1. DDL commands (Create, Alter, Drop)
2. DML commands (Insert, Update, Delete)
3. Functions (Number, Aggregate, character, conversion, Date)
4. Operators (Arithmetic, Logical, Comparison, Special, Set)
5. Group By & Having, Order By
6. Sub queries (including WHERE and ORDER BY, HAVING condition)
7. Views (create, insert, delete)
8. Constraints (Not null, unique, primary key, foreign key, default, check,
index)
9. Join operations (inner, full, left, right)
SCENARIO
The “Amazon Services” is a retail company with department stores in many major US cities.
The company has a large number of employees and sells a varied line of products. To
manage all information about the company structure and products, a database system is
used. The company consists of a number of stores that contain a number of departments. The
company has a number of employees, who (among other things) sell items at the different
stores. Sales are registered in the sale and debit tables. The sale and debit tables may be a bit
tricky to understand. You can view a row in the debit table as representing the receipt you
get when you pay for your items, while a row in the sale table represents a row on such a
receipt.
The company has contracts with various suppliers, who supply items for sale and also parts
for the company’s computer equipment. Deliveries of computer parts are registered in the
supply table. The current state of the company database can be seen in the ER diagram given
in Appendix A and the table definitions and contents in the appendixes B and C.
3. List the name of all departments, i.e. the NAME attribute for all tuples in the DEPT relation.
5. Perform Number and Aggregate functions on salary using specific conditions WHERE.
6. Display current Date for the sales and debit tables.
7. Retrieve all items sold in the department 49 with their name, price, and price increased
by10%.
8. Which employees have a family name starting with “S”? Retrieve their names, numbers and
salaries.
9. What are the names and weights of all parts delivered by a supplier called “DEC”?
16. Merge the two tables Suppliers and Departments using different JOIN operations for different
conditions.
17. For each supplier in Massachusetts (“Mass”) retrieve the total weight of all the parts delivered
by the supplier.
18. Insert data about a new supplier on your choice in the supplier table. Note that the city column
is a foreign key to the city table, i.e. the supplier city must already exist or be inserted in
advance to the city table.
19. All departments in store number 8 showed good sales figures last year! Give the managers of
these departments 5% raise of their salaries. Retrieve the information about these managers by
their first names.
20. Perform create, insert and delete operations on View of table Employees.