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

assignment5

The document outlines SQL commands for creating and managing two tables, Employees and EmployeeInfo, with relevant fields and relationships. It includes data insertion for employee records and their respective information, as well as the creation and modification of a view named EmployeeView to display employee names and hiring dates. The document also demonstrates how to filter the view based on the year of hiring.

Uploaded by

Iqŕa Nooŕ
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

assignment5

The document outlines SQL commands for creating and managing two tables, Employees and EmployeeInfo, with relevant fields and relationships. It includes data insertion for employee records and their respective information, as well as the creation and modification of a view named EmployeeView to display employee names and hiring dates. The document also demonstrates how to filter the view based on the year of hiring.

Uploaded by

Iqŕa Nooŕ
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment : 05

Name : Muhammad Sohaib


Reg no : DS231048
CREATE TABLE Employees (

EmployeeID INT PRIMARY KEY AUTO_INCREMENT,

First_name VARCHAR(50),

Date_of_Hiring DATE

);

CREATE TABLE EmployeeInfo ( EmployeeID INT PRIMARY KEY,

Department VARCHAR(50),

Salary DECIMAL(10, 2),

FOREIGN KEY (EmployeeID) REFERENCES Employees(EmployeeID)

);

CREATE OR REPLACE VIEW EmployeeView AS

SELECT First_name, Date_of_Hiring

FROM Employees;

INSERT INTO Employees (First_name, Date_of_Hiring)

VALUES ('hayyan', '2024-05-19'),

('ali', '2012-12-19'),

('kashif', '2020-08-16'),

('jawaid', '2019-04-10'),

('ayesha', '2021-11-25'),

('Sania', '2018-06-30'),

('noman', '2018-06-30'),

('bisma', '2018-06-30');

INSERT INTO EmployeeInfo (EmployeeID, Department, Salary)

VALUES (1, 'Admin', 50000.00),


(2, 'Production', 60000.00),

(3, 'IT', 55000.00),

(4, 'Marketing', 52000.00),

(5, 'Sales', 58000.00),

(6, 'Media', 58000.00),

(7, 'HR', 58000.00),

(8, 'Engineering', 65000.00);

SELECT * FROM Employees;

SELECT * FROM EmployeeInfo;

SELECT * FROM EmployeeView;

DROP VIEW IF EXISTS EmployeeView;

CREATE VIEW EmployeeView AS

SELECT First_name, Date_of_Hiring

FROM Employees

WHERE YEAR(Date_of_Hiring) = 2020;

SELECT * FROM Employees;

SELECT * FROM EmployeeInfo;

SELECT * FROM EmployeeView;

You might also like