You are on page 1of 3

Database Management System( ISM-231)

Final Project
Marks-10

Use SQL command to create the following Table (emp),


Exercise 1: Demonstrate the aggregate functions on emp table showing
maximum, minimum, sum and average salaries for managers and analysts.
Answer :

SELECT job, SUM(sal), AVG(sal), MAX(sal), MIN(sal)


FROM emp
WHERE job ="manager" OR job="Saleman"
GROUP BY job;

Exercise 2: Demonstrate the aggregate functions on emp table showing


maximum, minimum, sum and average salaries using having clause for different
departments.
Answer :

SELECT city, SUM(sal), AVG(sal), MAX(sal), MIN(sal)


FROM emp
GROUP BY city;
HAVING DISTINCT (city)
Make screenshot for each command:
empno ename Job Sal City
1 Ali manager 20000 Abha
2 Turki secretary 3000 Jeddah
3 Hamed saleman 20000 Abha
4 Salim saleman 3000 Riyahd
5 Mohamed manager 25000 Dammam
6 Fahad secretary 3000 Riyahd
 Apply SQL commands and make screenshot for each command: (5 marks)

A- Apply the following constraints on the Course Table:

 primary Key
ALTER table Course
ADD PRIMARY KEY (courseno);
 not null
ALTER TABLE Course
MODIFY courseno int NOT NULL;
 check
ALTER table Course ADD CHECK(courseno > 0);

courseno Cname crhr days time


CPE210 DBMS 3 13 10:00 - 10:50 AM

CPE122 OOP 3 24 09:00 – 09:50 AM

CPE220 Microprocessors 3 13 11:00 – 11:50 AM

B- Apply the foreign key constraints on the following two teacher and course tables given
below: (Note: insert data in the two tables)
Teacherno Teachername officeno

courseno Coursename crhr days Teacherno

Answer :

ALTER table Course


ADD FOREIGN KEY (Teacherno) REFERENCES teacherl(Teacherno);

Best Wishes......
Teacher Name: Fatimah Alqahtani.

You might also like