7349 Assignment2
7349 Assignment2
-- ================================================
-- Step 1: Create Employees and Departments Tables with specified columns and
constraints
CREATE TABLE Departments (
dept_id INT PRIMARY KEY,
dept_name VARCHAR(50) NOT NULL
);
-- Step 3: Left Join Query to retrieve employee id, name along with department name
SELECT e.emp_id, e.emp_name, d.dept_name
FROM Employees AS e
LEFT JOIN Departments AS d ON e.dept_id = d.dept_id;
-- Step 7: Insert 3 more records into Employees table and view the updated data
INSERT INTO Employees (emp_id, emp_name, salary, dept_id) VALUES
(6, 'Neo', 6500, 2),
(7, 'Trinity', 7000, 2),
(8, 'Morpheus', 5800, 3);
SELECT * FROM EmployeeDepartmentView;
-- Step 10: Delete records from view where employee salary is 8000
DELETE FROM Employees WHERE salary = 8000;
SELECT * FROM EmployeeDepartmentView;
-- ================================================
-- Additional Queries with Employee and Project Tables
-- ================================================
-- Step 12: Create Employee and Project Tables with specified columns
CREATE TABLE ProjectLocations (
proj_id INT PRIMARY KEY,
addr VARCHAR(50) NOT NULL
);
-- 10. Addresses where employees belong and projects are located (Union operation)
SELECT addr FROM Staff
UNION
SELECT addr FROM ProjectLocations;