0% found this document useful (0 votes)
20 views2 pages

SQL Lab Exercise Update Delete

The lab exercise focused on using SQL UPDATE and DELETE statements to modify and remove records in a database. It emphasized the importance of applying appropriate WHERE clauses to avoid unintentional data changes. The exercise included creating a table, executing update and delete queries, and observing the results.
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)
20 views2 pages

SQL Lab Exercise Update Delete

The lab exercise focused on using SQL UPDATE and DELETE statements to modify and remove records in a database. It emphasized the importance of applying appropriate WHERE clauses to avoid unintentional data changes. The exercise included creating a table, executing update and delete queries, and observing the results.
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

Lab Exercise Report

Title: Use UPDATE and DELETE Queries Efficiently

Objective:

To learn how to update existing records and delete records from a table using SQL UPDATE and
DELETE statements.

Theory:

- The UPDATE statement is used to modify existing records in a table.


- The DELETE statement removes existing records.

Efficient use of these commands includes applying appropriate WHERE clauses to prevent
unintentional data changes or loss.
Syntax:
UPDATE table_name SET column1 = value1 WHERE condition;
DELETE FROM table_name WHERE condition;

SQL Queries Executed:

CREATE DATABASE UpdateDeleteDemo;

USE UpdateDeleteDemo;

CREATE TABLE Employees (


EmpID INT PRIMARY KEY,
Name VARCHAR(100),
Department VARCHAR(50),
Salary FLOAT
);

INSERT INTO Employees (EmpID, Name, Department, Salary) VALUES


(1, 'Alice Brown', 'HR', 40000),
(2, 'Bob Smith', 'IT', 50000),
(3, 'Charlie Rose', 'Finance', 45000);
-- Update salary of employee in IT
UPDATE Employees SET Salary = 55000 WHERE Department = 'IT';

-- Delete employee from HR


DELETE FROM Employees WHERE Department = 'HR';

-- Select all records


SELECT * FROM Employees;

Output:

| EmpID | Name | Department | Salary |


|-------|--------------|------------|---------|
|2 | Bob Smith | IT | 55000.0 |
|3 | Charlie Rose | Finance | 45000.0 |

Screenshot of Query Execution:

*Placeholder - [Insert your screenshot here]*

Observation:

- The UPDATE query modified the salary of the employee in the IT department.
- The DELETE query removed the HR department employee.
- Remaining records reflect the changes accurately.

Conclusion:

This lab demonstrated efficient use of UPDATE and DELETE SQL statements. Proper use of
conditions in these statements helps in preventing accidental data loss or incorrect modifications.

You might also like