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

Create Database HRM

Uploaded by

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

Create Database HRM

Uploaded by

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

CREATE DATABASE HRM;

GO

USE HRM;

GO

Step 2: Create Tables

Table 1: Department

sql

Copy

CREATE TABLE Department (

DepID CHAR(10) NOT NULL PRIMARY KEY,

DepName CHAR(50)

);

Table 2: Employee

sql

Copy

CREATE TABLE Employee (

EmpID CHAR(50) NOT NULL PRIMARY KEY,

FName CHAR(50),

LName CHAR(50),

Sex CHAR(10),

DOB DATETIME,

HiredDate DATETIME,

Salary NUMERIC,
DepID CHAR(10) NOT NULL,

FOREIGN KEY (DepID) REFERENCES Department(DepID)

);

Table 3: Training

sql

Copy

CREATE TABLE Training (

EmpID CHAR(10) NOT NULL,

TrainingID CHAR(10) NOT NULL,

Title CHAR(10),

LastName CHAR(50),

Duration CHAR(10),

PRIMARY KEY (EmpID, TrainingID),

FOREIGN KEY (EmpID) REFERENCES Employee(EmpID)

);

Step 3: Insert Records

Insert Departments

sql

Copy

INSERT INTO Department (DepID, DepName) VALUES

('0111', 'Finance'),

('0112', 'Human Resource'),

('0113', 'Information Technology');


Insert Employees

sql

Copy

INSERT INTO Employee (EmpID, FName, LName, Sex, DOB, HiredDate, Salary, DepID) VALUES

('E001', 'Abebe', 'Mekasha', 'M', '1950-12-04', '1987-06-15', 4000, '0111'),

('E002', 'Tewodrose', 'Sileshi', 'M', '1975-05-27', '1996-03-27', 3000, '0113'),

('E003', 'Selam', 'Nigussie', 'F', '1986-04-09', '2006-12-05', 1500, '0114'),

('E004', 'Bekele', 'Abera', 'M', '1967-12-03', '2000-05-13', 10000, '0115'),

('E005', 'Taye', 'Daniel', 'M', '1980-05-13', '2000-04-06', 2500, '0114');

Insert Training Records

sql

Copy

INSERT INTO Training (EmpID, TrainingID, Title, LastName, Duration) VALUES

('E001', '000', 'ICT', 'Belay', '1 month'),

('E002', '001', 'Accounting', 'Neuro', '2 months'),

('E003', '002', 'Oracle', 'Ava', '4 months'),

('E004', '003', 'Mgmt', 'Emi', '3 months'),

('E005', '004', 'Strategic Planning', 'Emi', '1 month');

Step 4: Additional Queries

Insert a New Department

sql

Copy
INSERT INTO Department (DepID, DepName) VALUES ('0116', 'Marketing');

Display Employee Records

sql

Copy

SELECT EmpID, FName, LName, DepID FROM Employee;

Total Salary by Department

sql

Copy

SELECT DepID, SUM(Salary) AS TotalSalary

FROM Employee

GROUP BY DepID;

Increase Salary by 20%

sql

Copy

UPDATE Employee

SET Salary = Salary * 1.20;

Delete Record Containing 'zelalme'

sql

Copy

DELETE FROM Employee

WHERE LName = 'zelalme';


Update Employee First Name

sql

Copy

UPDATE Employee

SET FName = 'TOLA'

WHERE EmpID = 'E001';

Select All Records from Employee Table

sql

Copy

SELECT * FROM Employee;

Select Specific Fields with Salary Condition

sql

Copy

SELECT EmpID, FName, Sex

FROM Employee

WHERE Salary > 1500;

Select Employees Whose First Name Starts with 'M'

sql

Copy

SELECT *

FROM Employee
WHERE FName LIKE 'M%';

Select Employees with First Name Matching 'b-k-le'

sql

Copy

SELECT *

FROM Employee

WHERE FName LIKE 'b_k_le';

Select Employees Whose First Name Does Not Contain 'A'

sql

Copy

SELECT *

FROM Employee

WHERE FName NOT LIKE '%A%';

You might also like