Assign 1
Assign 1
Assignment 1
Scenario
You are working as a database developer for a company that needs to manage its employee
records, departments, and projects. Your task is to create a database
named EmployeeManagementSystem and design the necessary tables to store the data. The
company has provided you with the following requirements:
1. Departments Table
The company has multiple departments, each with a unique name and location.
Each department has a unique DepartmentID (primary key).
The DepartmentName must be unique, and the Location cannot be null.
2. Employees Table
The company has employees who belong to different departments.
Each employee has a unique EmployeeID (primary key).
The employee's FirstName, LastName, Email, and Phone are required fields.
The Email and Phone must be unique for each employee.
The HireDate should default to the current date if not provided.
The Salary must be greater than 0.
Each employee belongs to a department, so the DepartmentID is a foreign key
referencing the Departments table.
If a department is deleted, the DepartmentID for employees in that department should
be set to NULL.
If a department's DepartmentID is updated, the change should cascade to the
Employees table.
3. Projects Table
The company manages multiple projects, each assigned to a department.
Each project has a unique ProjectID (primary key).
The ProjectName, StartDate, and EndDate are required fields.
The EndDate must be greater than the StartDate.
Each project is assigned to a department, so the DepartmentID is a foreign key
referencing the Departments table.
If a department is deleted, all projects assigned to that department should also be
deleted.
If a department's DepartmentID is updated, the change should not affect the Projects
table.
Write SQL queries to complete the following tasks:
1. Create a database named EmployeeManagementSystem.
2. Use the database for the subsequent tasks.
3. Create the Departments table with the required columns and constraints.
4. Create the Employees table with the required columns and constraints.
5. Create the Projects table with the required columns and constraints.
Insert Data into Tables
1. Insert the following departments into the Departments table:
HR, Location: New York
IT, Location: San Francisco
Finance, Location: Chicago
2. Insert the following employees into the Employees table:
John Doe, Email: [email protected], Phone: 1234567890, Salary: 50000,
Department: HR
Jane Smith, Email: [email protected], Phone: 9876543210, Salary: 60000,
Department: IT
Alice Johnson, Email: [email protected], Phone: 5555555555, Salary: 55000,
Department: Finance
Bob Brown, Email: [email protected], Phone: 1111111111, Salary: 70000,
Department: IT
Charlie Davis, Email: [email protected], Phone: 2222222222, Salary: 65000,
Department: HR
3. Insert the following projects into the Projects table:
Project A, StartDate: 2023-01-01, EndDate: 2023-06-30, Department: IT
Project B, StartDate: 2023-02-01, EndDate: 2023-08-31, Department: HR
Project C, StartDate: 2023-03-01, EndDate: 2023-09-30, Department: Finance
Submit the SQL script containing all the commands you executed.