0% found this document useful (0 votes)
3 views4 pages

Lab 2

The document outlines SQL commands for creating and managing two tables: STUDENT and Employee. It includes tasks for updating records, deleting entries, and querying data based on specific conditions. Additionally, it provides an example of applying a salary increase to employees with the job title 'Manager'.

Uploaded by

tusharrg017
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)
3 views4 pages

Lab 2

The document outlines SQL commands for creating and managing two tables: STUDENT and Employee. It includes tasks for updating records, deleting entries, and querying data based on specific conditions. Additionally, it provides an example of applying a salary increase to employees with the job title 'Manager'.

Uploaded by

tusharrg017
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/ 4

LAB_2

CREATE TABLE STUDENT(


Student_Id SERIAL Primary KEY,
First_Name VARCHAR(20) NOT NULL,
LASTNAME VARCHAR(20) NOT NULL,
DATEOFBIRTH DATE NOT NULL,
GENDER VARCHAR(10),
EMAIL VARCHAR(50) UNIQUE,
PHONE VARCHAR(15) UNIQUE CHECK (LENGTH(PHONE)>=10)
);

INSERT INTO STUDENT


VALUES
(1001,'Raj','Sharma','2000-01-15','M','[email protected]',6818616799),
(1002,'Priya','Singh','2001-03-22','F','[email protected]',9974646981),
(1003, 'Arjun', 'Verma','2001-06-01','M','[email protected]',7349448457),
(1004, 'Suman', 'Patel','2000-07-30','F','[email protected]',9733546311),
(1005, 'Kavita', 'Rao','2002-11-10','F','[email protected]',6895626259),
(1006, 'Neha', 'Desai','1999-05-18','F','[email protected]',9997859389),
(1007,'Jane','Smith','2000-03-15','F','[email protected]',1234567890),
(1008,'Roger','White','1999-12-01','M','[email protected]',9634812664);

--TASK_1--
UPDATE STUDENT
SET EMAIL = '[email protected]'
WHERE First_Name = 'Jane' AND LASTNAME = 'Smith';
UPDATE STUDENT
SET EMAIL = '[email protected]'
WHERE First_Name = 'Roger' AND LASTNAME = 'White';
--TASK_2--
DELETE FROM STUDENT
WHERE LASTNAME = 'Smith';
--TASK_3--
SELECT * FROM STUDENT WHERE First_Name LIKE'J%';

LAB_3
CREATE TABLE Employee(
emp_id SERIAL PRIMARY KEY,
First_Name VARCHAR(20) NOT NULL,
Last_Name VARCHAR(20) NOT NULL,
AGE INT NOT NULL,
email_id varchar(40),
PHONE VARCHAR(15) UNIQUE CHECK (LENGTH(PHONE)>=10)
);
--TASK_1--
INSERT INTO Employee
VALUES
(1001,'Raj','Sharma',20,'[email protected]',6818616799),
(1002,'Priya','Singh',32,'[email protected]',9974646981),
(1003, 'Arjun', 'Verma',26,'[email protected]',7349448457),
(1004, 'Suman', 'Patel',27,'[email protected]',9733546311),
(1005, 'Kavita', 'Rao',22,'[email protected]',6895626259),
(1006, 'Neha', 'Desai',18,'[email protected]',9997859389),
(1007,'Jane','Smith',25,'[email protected]',1234567890),
(1008,'Roger','White',19,'[email protected]',9634812664);
--TASK_2--
SELECT emp_id,First_Name,Last_Name FROM Employee;

--TASK_3--
SELECT emp_id,First_Name,Last_Name FROM Employee WHERE AGE = 30;
--TASK_4--
UPDATE Employee
SET AGE = (AGE+1)
WHERE AGE > 25;
SELECT * FROM Employee;

----ChatGPT Exercise----
To apply a 10% salary increase only to employees with the job title "Manager," you
can use an SQL UPDATE query with a WHERE clause to filter the employees by job
title. Here's the SQL query:
UPDATE employees
SET salary = salary * 1.10
WHERE job_title = 'Manager';
Explanation:
• UPDATE employees: Specifies the table to update (in this case, the employees
table).
• SET salary = salary * 1.10: Increases the salary by 10% (multiplying the current
salary by 1.10).
• WHERE job_title = 'Manager': Limits the update to employees with the job
title "Manager".

You might also like