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

create and insert

The document outlines the creation of a database named 'logic' with tables for Employees, Departments, Projects, and Employee_Projects. It includes the structure of each table, their relationships through foreign keys, and inserts initial data into these tables. The data covers various departments, employees with their details, and projects along with employee assignments to those projects.

Uploaded by

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

create and insert

The document outlines the creation of a database named 'logic' with tables for Employees, Departments, Projects, and Employee_Projects. It includes the structure of each table, their relationships through foreign keys, and inserts initial data into these tables. The data covers various departments, employees with their details, and projects along with employee assignments to those projects.

Uploaded by

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

create database logic;

use logic;

CREATE TABLE Employees (


employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
department_id INT,
hire_date DATE,
salary DECIMAL(10,2),
FOREIGN KEY (department_id) REFERENCES Departments(department_id)
);

CREATE TABLE Departments (


department_id INT PRIMARY KEY,
department_name VARCHAR(50),
location VARCHAR(50)
);

CREATE TABLE Projects (


project_id INT PRIMARY KEY,
project_name VARCHAR(50)
);

CREATE TABLE Employee_Projects (


employee_id INT,
project_id INT,
FOREIGN KEY (employee_id) REFERENCES Employees(employee_id),
FOREIGN KEY (project_id) REFERENCES Projects(project_id)
);

INSERT INTO Departments (department_id, department_name, location) VALUES


(1, 'IT', 'New York'),
(2, 'HR', 'Chicago'),
(3, 'Finance', 'Los Angeles'),
(4, 'Marketing', 'San Francisco');

INSERT INTO Employees (employee_id, first_name, last_name, department_id,


hire_date, salary) VALUES
(101, 'Alice', 'Johnson', 1, '2015-06-23', 75000.00),
(102, 'Bob', 'Smith', 1, '2018-09-15', 65000.00),
(103, 'Charlie', 'Brown', 2, '2016-07-30', 60000.00),
(104, 'David', 'Williams', 2, '2020-01-10', 50000.00),
(105, 'Eve', 'Davis', 3, '2012-05-14', 90000.00),
(106, 'Frank', 'Miller', 3, '2019-03-21', 70000.00),
(107, 'Grace', 'Wilson', 4, '2017-11-11', 55000.00),
(108, 'Hank', 'Moore', 4, '2021-08-05', 48000.00);
INSERT INTO Projects (project_id, project_name) VALUES
(201, 'Cloud Migration'),
(202, 'HR Automation'),
(203, 'Financial Analysis'),
(204, 'Social Media Campaign');

INSERT INTO Employee_Projects (employee_id, project_id) VALUES


(101, 201),
(102, 201),
(103, 202),
(104, 202),
(105, 203),
(106, 203),
(107, 204),
(108, 204),
(101, 203), -- Alice also works on Financial Analysis
(105, 201); -- Eve also works on Cloud Migration

You might also like