Mekelle Institute of Technology (MIT) Mekelle, Tigray, Ethiopia
Mekelle Institute of Technology (MIT) Mekelle, Tigray, Ethiopia
Mekelle Institute of Technology (MIT) Mekelle, Tigray, Ethiopia
Lab manual : 4
For this week’s lab exercise you are going to prepare a document that contains
all your work and submit it for grading. The first three lines of your document
should contain your name, id number and lab exercise number like what is
shown in the example below.
Example:
Make sure you include an answer for all the questions in the lab manual and
provide a comment for each statement. Your MySQL statements should look
like this:
1. Create the following tables in the database CSEIT that you have created
during lab exercise 3. These tables are going to be used for this lab exercise
and for the future lab-exercises. The schema of each table is shown below.
Be careful to choose the best data type for each column and to follow the
general naming conventions. Students who ignore such rules are going to
lose some marks. You should have to identify the appropriate primary key
for each table. Remember that every table in the database must have a
primary key to enforce the entity integrity and if there is a relationship
between tables a foreign key is necessary. Also apply some useful
constraints while creating your tables.
EMPLOYEE :( EMP_ID, EMP_FNAME, EMP_LNAME, EMP_GENDER, EMP_AGE,
EMP_SALARY).
DEPARTMENT :( EMP_ID, DEPT_CODE, DEPT_NAME).
COURSE :( EMP_ID, COURSE_CODE, CREDIT_HOURS, COURSE_NAME)
2. After creating the tables, populate each table with the following data:
EMPLOYEE TABLE:
F 26 2800.0000
M 200 1900.0000
M 30 2000.0000
M 45 2010.0000
M 26 900.0000
M 29 1900.0000
M 22 1700.0000
M 20 1200.0000
M 18 12000.0000
M 15 13000.0000
M 29 11000.0000
M 310 1982.0000
M 20 1900.0000
M 27 4000.000
M 18 21000.0000
M 15 31000.0000
M 29 1000.0000
M 301 2982.0000
M 28 1900.0000
F 20 1980.000
DEPARTMENT TABLE:
EMP_ID DEPT_CODE DEPT_NAME
COURSE TABLE:
EMP_ID COURSE_CODE CREDIT_HOURS COURSE_NAME
MIT/2000/7 MC 4 MICROCONTROLLERS
4. Write a query that retrieves the details of the employees from the EMPLOYEE table arranged by
age in ascending order
5. ADD a column named WORKING_HRS in the EMPLOYEE table and insert valid values into that
column.
7. Change the data type of the column EMP_FNAME to char (30) and change it again into varchar (30).
8. Add a constraint called const_check that checks the salary of a specific employee is greater than
100 birr.
10. Write a query that gives you information about the employees and their department.
11. Write a query that gives you information about courses and the instructors handling these courses.
12. Write a query that retrieves all rows from the EMPLOYEE table where the age of the employees
is greater than 20.
13. Using IN write a query that retrieves the details of all the employees who are working in the
department of Information Technology.
14. Write a query that retrieves the details of the eldest employee.
15. Write a query that retrieves every detail of the departments order by department name.
16. Now rewrite the query in 15 in a way that it will retrieve a list of unique departments only.
17. Remember that using the COUNT (*) aggregate function returns a count of all rows in a table.
Write a query to return a count of the rows in the COURSES table.
18. If you want to avoid using an asterisk with COUNT (*), it is possible to use select column name,
COUNT (column name).Write the query number 17 using this method. Is there a difference with the
former one?
19. LIKE statement allows you to use wildcards in your comparisons. Using LIKE statement write a
query that lists the details of all employees whose first name start with the letter ‘M’
20. IN also allows you to compare a single column to a list of values. For example, if you want to
retrieve a list of all employees whose age is 20, 25, or 30. Write a query using IN that can accomplish
this task.
21. BETWEEN allows you to check if a column contains a value that is greater than or equal to one
value and less than or equal to another. Write a query that lists all employees whose age is between 20
and 30.
22. Write a query that returns the details of male employees who are elder than 30 and with salary
greater than or equal to 1800.00birr.
23. Write a query that returns the details of employees who are not elder than 30 and whose salary is
not equal to 1800.00birr.
*24. Write a query that retrieves the names of employees whose salary is greater than mine. {You will
get a bonus for this.}