Mastering the Essentials: A Guide to SQL Update, Delete, and Truncate Commands

Mesum.H
3 min readApr 4, 2023

--

Welcome to my blog on SQL commands of update, delete, and truncate! SQL is a powerful language used for managing data in relational databases, and these three commands are essential for manipulating data within a table. Each command has its own specific use case and understanding their differences can help you choose the right command for your needs.

In this blog, I will provide an overview of the update, delete, and truncate commands, their syntax, and examples of how to use them effectively. Whether you’re a beginner or an experienced SQL user, this blog will help you enhance your knowledge of these crucial commands.

Task1: Updating the record in the table

Original BOOKS_DATA:

Command:

Result:

Task 2: Inserting more rows in the table

Initial table:

Command:

Result:

Till now we have seen how to insert new data in the table and update the existing data. Next we will learn how to remove data from the table in SQL. There are basically two commands which are used for this purpose: DELETE and TRUNCATE. Both fulfills the same purpose but there is a key difference between them which is needs to addressed here.

Difference between DELETE and TRUNCATE:

DELETE is a Data Manipulation Language (DML) statement is used for manipulation purpose, while TRUNCATE being a Data Definition Language (DDL) statement is used for changing the structure of the table. Table below explains the differences well.

DELETE COMMAND

Command:

Result:

TRUNCATE COMMAND

Initial table ‘employees_data’:

Truncate Command:

Result: all the rows in the table are deleted permanently.

I hope this blog has provided you with a clear understanding of SQL commands of update, delete, and truncate. By mastering these commands, you can efficiently manage your data in relational databases and perform data manipulation tasks with ease.

Remember to always use these commands with caution and keep a backup of your data before making any changes. If you have any questions or suggestions, feel free to leave a comment below. Thank you for reading!

--

--

Mesum.H
Mesum.H

Written by Mesum.H

Fellow Data Engineer- Bytewise Ltd

No responses yet