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

Database lab 4

This document outlines a database lab focused on SQL queries, specifically using EXISTS, subqueries in the FROM clause, and the WITH clause. It includes tasks for creating tables for instructors and departments, inserting sample data, and formulating queries to analyze department budgets and instructor salaries. Students are required to submit screenshots of their executed queries and results as part of the lab submission.

Uploaded by

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

Database lab 4

This document outlines a database lab focused on SQL queries, specifically using EXISTS, subqueries in the FROM clause, and the WITH clause. It includes tasks for creating tables for instructors and departments, inserting sample data, and formulating queries to analyze department budgets and instructor salaries. Students are required to submit screenshots of their executed queries and results as part of the lab submission.

Uploaded by

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

Database lab 4

Objective:
This lab will help students practice SQL queries using EXISTS,
subqueries in the FROM clause, and WITH clause.

Task 1: Table Creation


Create the following tables to store instructor and department details.
CREATE TABLE department (
dept_name VARCHAR(50) PRIMARY KEY,
budget DECIMAL(12,2)
);

CREATE TABLE instructor (


ID INT PRIMARY KEY,
name VARCHAR(50),
dept_name VARCHAR(50),
salary DECIMAL(10,2),
FOREIGN KEY (dept_name) REFERENCES department(dept_name)
);

Task 2: Insert Sample Data


INSERT INTO department (dept_name, budget) VALUES
('Computer Science', 90000.00),
('Mathematics', 70000.00),
('Physics', 85000.00),
('Biology', 60000.00),
('Engineering', 120000.00);

INSERT INTO instructor (ID, name, dept_name, salary) VALUES


(101, 'Alice', 'Computer Science', 50000),
(102, 'Bob', 'Mathematics', 40000),
(103, 'Charlie', 'Physics', 45000),
(104, 'David', 'Mathematics', 43000),
(105, 'Eve', 'Computer Science', 55000),
(106, 'Frank', 'Physics', 41000),
(107, 'Grace', 'Biology', 39000);

Task 3: New Queries to Solve


1. Use EXISTS to find instructors who work in departments with a
budget greater than 80,000.
2. Use a subquery in the FROM clause to find the department with
the lowest average salary.
3. Use WITH clause to find departments where the total salary
paid is more than 85,000.

Submission Guidelines:
 Submit screenshots of your executed queries and results.

You might also like