By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
World of SoftwareWorld of SoftwareWorld of Software
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Search
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
Reading: SQL Data Modification Commands With Examples: A Fast and Easy Guide | HackerNoon
Share
Sign In
Notification Show More
Font ResizerAa
World of SoftwareWorld of Software
Font ResizerAa
  • Software
  • Mobile
  • Computing
  • Gadget
  • Gaming
  • Videos
Search
  • News
  • Software
  • Mobile
  • Computing
  • Gaming
  • Videos
  • More
    • Gadget
    • Web Stories
    • Trending
    • Press Release
Have an existing account? Sign In
Follow US
  • Privacy
  • Terms
  • Advertise
  • Contact
Copyright © All Rights Reserved. World of Software.
World of Software > Computing > SQL Data Modification Commands With Examples: A Fast and Easy Guide | HackerNoon
Computing

SQL Data Modification Commands With Examples: A Fast and Easy Guide | HackerNoon

News Room
Last updated: 2025/05/02 at 2:07 PM
News Room Published 2 May 2025
Share
SHARE

Introduction

SQL is not just about querying data—it also includes powerful commands to modify data within tables. These Data Manipulation Language (DML) commands, such as INSERT, UPDATE, and DELETE, enable you to add, modify, or remove rows in a database. In this article, we’ll explore these commands with practical examples.

Sample Table: Employees

Let’s start with a sample Employees table to demonstrate the examples:

EmployeeID

Name

Position

Salary

Department

1

Alice

Developer

70000

IT

2

Bob

Designer

65000

Design

3

Charlie

Developer

72000

IT

4

Diana

Manager

90000

HR

5

Eve

Developer

70000

IT

1. INSERT: Adding Rows to a Table

The INSERT command is used to add new rows to a table.

Task: Add a new employee, Frank, who is a Tester in the QA department with a salary of $60,000.

INSERT INTO Employees (EmployeeID, Name, Position, Salary, Department)
VALUES (6, 'Frank', 'Tester', 60000, 'QA');

Result: The table now includes the new employee:

EmployeeID

Name

Position

Salary

Department

1

Alice

Developer

70000

IT

2

Bob

Designer

65000

Design

3

Charlie

Developer

72000

IT

4

Diana

Manager

90000

HR

5

Eve

Developer

70000

IT

6

Frank

Tester

60000

QA

2. UPDATE: Modifying Existing Rows

The UPDATE command allows you to modify data in existing rows based on specific conditions.

Task: Give all Developers in the IT department a 10% salary increase.

UPDATE Employees
SET Salary = Salary * 1.10
WHERE Position = 'Developer' AND Department = 'IT';

Result: The salary for Alice, Charlie, and Eve has been updated:

EmployeeID

Name

Position

Salary

Department

1

Alice

Developer

77000

IT

2

Bob

Designer

65000

Design

3

Charlie

Developer

79200

IT

4

Diana

Manager

90000

HR

5

Eve

Developer

77000

IT

6

Frank

Tester

60000

QA

3. DELETE: Removing Rows From a Table

The DELETE command removes rows from a table based on a condition.

Task: Remove all employees in the QA department.

DELETE FROM Employees
WHERE Department = 'QA';

Result: Frank has been removed from the table:

EmployeeID

Name

Position

Salary

Department

1

Alice

Developer

77000

IT

2

Bob

Designer

65000

Design

3

Charlie

Developer

79200

IT

4

Diana

Manager

90000

HR

5

Eve

Developer

77000

IT

4. MERGE (UPSERT): Combining Insert and Update

The MERGE statement is used to insert new rows or update existing rows based on a match condition. This is also known as “upsert”.

Task: If an employee with EmployeeID = 5 exists, update their position to “Lead Developer”. Otherwise, insert a new employee.

MERGE INTO Employees AS Target
USING (SELECT 5 AS EmployeeID, 'Eve' AS Name, 'Lead Developer' AS Position, 80000 AS Salary, 'IT' AS Department) AS Source
ON Target.EmployeeID = Source.EmployeeID
WHEN MATCHED THEN
    UPDATE SET Position = Source.Position, Salary = Source.Salary
WHEN NOT MATCHED THEN
    INSERT (EmployeeID, Name, Position, Salary, Department)
    VALUES (Source.EmployeeID, Source.Name, Source.Position, Source.Salary, Source.Department);

Result: Eve’s position has been updated to “Lead Developer”:

EmployeeID

Name

Position

Salary

Department

1

Alice

Developer

77000

IT

2

Bob

Designer

65000

Design

3

Charlie

Developer

79200

IT

4

Diana

Manager

90000

HR

5

Eve

Lead Developer

80000

IT

5. TRUNCATE: Quickly Clearing All Rows

The TRUNCATE command removes all rows from a table, but unlike DELETE, it does not log individual row deletions, making it faster.

Task: Clear all rows from the Employees table.

TRUNCATE TABLE Employees;

Result: The table is now empty, but the structure remains intact.

6. DROP: Removing the Entire Table

The DROP command deletes a table and its data permanently.

Task: Remove the Employees table from the database.

DROP TABLE Employees;

Result: The Employees table no longer exists.

Summary

SQL provides a wide range of commands to modify data and table structures. Here’s a quick recap:

Command Use Case

  1. INSERT: Add new rows to a table.
  2. UPDATE: Modify data in existing rows.
  3. DELETE: Remove specific rows from a table.
  4. MERGE: Combine insert and update logic (upsert).
  5. TRUNCATE: Quickly clear all rows in a table.
  6. DROP Remove the entire table structure and data.

These commands allow you to keep your database up-to-date, clean, and well-organized. Practice these examples on your own database to gain confidence in modifying data with SQL!


Thank you for taking the time to explore data-related insights with me. I appreciate your engagement. If you find this information helpful, I invite you to follow me or connect with me on LinkedIn. Happy exploring!👋

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Email Print
Share
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Palace breaks silence after Harry blamed Royals & said ‘king won’t speak to me’
Next Article The Week’s Biggest Funding Rounds: Investors Look To The Stars And Defense
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

248.1k Like
69.1k Follow
134k Pin
54.3k Follow

Latest News

Apple’s new white-knuckle wildfire drama stars Matthew McConaughey as a heroic bus driver
News
Iranian Hacker Pleads Guilty in $19 Million Robbinhood Ransomware Attack on Baltimore
Computing
iOS 19: All the rumored changes Apple could be bringing to its new operating system | News
News
How to Turn Off Meta AI Features on Facebook, Instagram or WhatsApp
News

You Might also Like

Computing

Iranian Hacker Pleads Guilty in $19 Million Robbinhood Ransomware Attack on Baltimore

3 Min Read
Computing

Box64 v0.3.6 Brings Better AVX Handling, Volatile Metadata For Windows Executables

2 Min Read
Computing

DJI to build global smart aviation headquarters in Shenzhen after acquiring plot for $315 million · TechNode

1 Min Read
Computing

3 Ways Large Brands Grow & Experiment on Social Media

3 Min Read
//

World of Software is your one-stop website for the latest tech news and updates, follow us now to get the news that matters to you.

Quick Link

  • Privacy Policy
  • Terms of use
  • Advertise
  • Contact

Topics

  • Computing
  • Software
  • Press Release
  • Trending

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

World of SoftwareWorld of Software
Follow US
Copyright © All Rights Reserved. World of Software.
Welcome Back!

Sign in to your account

Lost your password?