0% found this document useful (0 votes)
46 views6 pages

DBMS - Assignment - Roshan Kumar Thapa - 1

Uploaded by

sw.dvbimal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views6 pages

DBMS - Assignment - Roshan Kumar Thapa - 1

Uploaded by

sw.dvbimal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Master of Information Technology (MIT)

September Intake 2023


Second Semester

Assignment
SQL Database Implementation for IT Company Management System

Database Management (CSC 5400)

Submitted By: Submitted To:


Roshan Kumar Thapa Devashish Gupta

Submitted for the partial fulfillment of the assignment Requirements Engineering


(MIT)

Date: 13th June 2024


Question: Create a new database named "ITCompanyManagementSystem."

• Translate each entity from the ERD into SQL tables with appropriate data
types and constraints.
• Add Foreign Key constraints to enforce the relationships identified in the
ERD
• Implement any additional constraints mentioned in the ERD.
• Provide the SQL script for creating the database, tables, relationships, and
constraints.
• Include sample data insertion statements for each table.
• Write queries to retrieve information like all employees working on a
project, projects managed by a team lead, etc.on: SQL Database
Implementation for IT Company Management System

This assignment assesses your ability to translate ERD concepts into a working
relational database using SQL. Ensure that your SQL script accurately reflects
the specified requirements and constraints.

• Correctness and completeness of SQL script.


• Adherence to the specified requirements.
• Appropriateness of data types and constraints.
• Clarity and efficiency of SQL queries.
Below is the SQL script to create the database "ITCompanyManagementSystem,"
including the creation of tables, relationships, and constraints, as well as sample data
insertion statements and example queries.

Create Database and Tables with Constraints


-- Create the database
CREATE DATABASE ITCompanyManagementSystem;

-- Use the database


USE ITCompanyManagementSystem;

-- Create Employee table


CREATE TABLE Employee (
EmployeeID INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Position VARCHAR(50),
Email VARCHAR(100) UNIQUE NOT NULL,
DateOfJoining DATE NOT NULL,
Skillset TEXT
);

-- Create Client table


CREATE TABLE Client (
ClientID INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(100) NOT NULL,
Industry VARCHAR(50),
ContactPerson VARCHAR(100),
ContactEmail VARCHAR(100),
ContactPhone VARCHAR(20)
);

-- Create Project table


CREATE TABLE Project (
ProjectID INT PRIMARY KEY AUTO_INCREMENT,
Title VARCHAR(100) NOT NULL,
StartDate DATE,
EndDate DATE,
Status VARCHAR(50),
ClientID INT,
FOREIGN KEY (ClientID) REFERENCES Client(ClientID)
);

-- Create Technology table


CREATE TABLE Technology (
TechID INT PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(50) NOT NULL,
Description TEXT
);

-- Create Team table


CREATE TABLE Team (
TeamID INT PRIMARY KEY AUTO_INCREMENT,
TeamLeadEmployeeID INT,
ProjectID INT,
FOREIGN KEY (TeamLeadEmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (ProjectID) REFERENCES Project(ProjectID)
);

-- Create associative table for Employee and Project (Many-to-Many)


CREATE TABLE Employee_Project (
AssignmentID INT PRIMARY KEY AUTO_INCREMENT,
EmployeeID INT,
ProjectID INT,
HoursWorked INT,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (ProjectID) REFERENCES Project(ProjectID),
CONSTRAINT UniqueEmployeeProject UNIQUE (EmployeeID, ProjectID)
);

-- Create associative table for Project and Technology (Many-to-Many)


CREATE TABLE Project_Technology (
UsageID INT PRIMARY KEY AUTO_INCREMENT,
ProjectID INT,
TechID INT,
FOREIGN KEY (ProjectID) REFERENCES Project(ProjectID),
FOREIGN KEY (TechID) REFERENCES Technology(TechID),
CONSTRAINT UniqueProjectTechnology UNIQUE (ProjectID, TechID)
);

-- Create table for Employee and Team (One-to-Many)


CREATE TABLE Employee_Team (
ManagementID INT PRIMARY KEY AUTO_INCREMENT,
EmployeeID INT,
TeamID INT,
FOREIGN KEY (EmployeeID) REFERENCES Employee(EmployeeID),
FOREIGN KEY (TeamID) REFERENCES Team(TeamID)
);

Sample Data Insertion


-- Insert sample data into Employee table
INSERT INTO Employee (Name, Position, Email, DateOfJoining, Skillset)
VALUES
('Alice Johnson', 'Developer', '[email protected]', '2020-01-15',
'Java, SQL'),
('Bob Smith', 'Manager', '[email protected]', '2018-03-20',
'Management, C++'),
('Carol White', 'Tester', '[email protected]', '2019-07-22',
'Testing, Python');

-- Insert sample data into Client table


INSERT INTO Client (Name, Industry, ContactPerson, ContactEmail,
ContactPhone) VALUES
('Tech Solutions', 'IT', 'David Brown', '[email protected]',
'555-1234'),
('Innovate LLC', 'Finance', 'Emma Green', '[email protected]', '555-
5678');

-- Insert sample data into Project table


INSERT INTO Project (Title, StartDate, EndDate, Status, ClientID)
VALUES
('Project Alpha', '2021-01-01', '2021-12-31', 'Completed', 1),
('Project Beta', '2022-01-01', NULL, 'Ongoing', 2);

-- Insert sample data into Technology table


INSERT INTO Technology (Name, Description) VALUES
('Java', 'Programming Language'),
('SQL', 'Database Language'),
('Python', 'Programming Language');
-- Insert sample data into Team table
INSERT INTO Team (TeamLeadEmployeeID, ProjectID) VALUES
(2, 1),
(1, 2);

-- Insert sample data into Employee_Project table


INSERT INTO Employee_Project (EmployeeID, ProjectID, HoursWorked)
VALUES
(1, 1, 100),
(2, 1, 50),
(3, 2, 75);

-- Insert sample data into Project_Technology table


INSERT INTO Project_Technology (ProjectID, TechID) VALUES
(1, 1),
(1, 2),
(2, 3);

-- Insert sample data into Employee_Team table


INSERT INTO Employee_Team (EmployeeID, TeamID) VALUES
(1, 1),
(2, 1),
(3, 2);

Example Queries

1. Retrieve all employees working on a specific project (e.g., ProjectID = 1):

SELECT e.Name, e.Position, e.Email, ep.HoursWorked


FROM Employee e
JOIN Employee_Project ep ON e.EmployeeID = ep.EmployeeID
WHERE ep.ProjectID = 1;

2. Retrieve all projects managed by a specific team lead (e.g.,


TeamLeadEmployeeID = 2):

SELECT p.Title, p.StartDate, p.EndDate, p.Status


FROM Project p
JOIN Team t ON p.ProjectID = t.ProjectID
WHERE t.TeamLeadEmployeeID = 2;

3. Retrieve technologies used in a specific project (e.g., ProjectID = 2):

SELECT t.Name, t.Description


FROM Technology t
JOIN Project_Technology pt ON t.TechID = pt.TechID
WHERE pt.ProjectID = 2;

4. Retrieve all clients and their projects:

SELECT c.Name AS ClientName, p.Title AS ProjectTitle, p.Status


FROM Client c
JOIN Project p ON c.ClientID = p.ClientID;

5. Retrieve all teams and their team leads:


SELECT t.TeamID, e.Name AS TeamLeadName
FROM Team t
JOIN Employee e ON t.TeamLeadEmployeeID = e.EmployeeID;

You might also like