How to Data Manipulation in SQL: A Beginner’s Guide(4)
SQL is a powerful language for working with data in databases. It allows you to create, query, modify, and control data in a structured and efficient way. In this blog post, we will focus on the data manipulation aspect of SQL, which involves inserting, updating, and deleting data in tables. These operations are also known as DML (Data Manipulation Language) statements.

Insert Statement:
The INSERT statement is used to add new rows of data to a table. The syntax of the INSERT statement is as follows
INSERT INTO table_name (column1, column2, …)
VALUES (value1, value2, …);
The table_name is the name of the table where you want to insert the data. The column names are optional, but they help to specify which columns you want to fill with values. The values are the data that you want to insert, and they should match the data type and constraints of the corresponding columns.
For example, suppose we have a table called customers with the following columns and data types: Table

To insert a new row of data into this table, we can use the following INSERT statement:

Update Statement:
The UPDATE statement is used to modify existing rows of data in a table. The syntax of the UPDATE statement is as follows:
UPDATE table_name
SET column1 = value1, column2 = value2, …
WHERE condition;
The table_name is the name of the table where you want to update the data. The SET clause specifies which columns you want to change and what values you want to assign to them. The WHERE clause is optional, but it helps to filter the rows that you want to update based on a condition. If you omit the WHERE clause, all the rows in the table will be updated.
For example, suppose we want to update the email and phone columns of the customers table for the customer with id 101. We can use the following UPDATE statement:

Delete Statement:
The DELETE statement is used to remove existing rows of data from a table. The syntax of the DELETE statement is as follows:
DELETE FROM table_name
WHERE condition;
The table_name is the name of the table where you want to delete the data. The WHERE clause is optional, but it helps to filter the rows that you want to delete based on a condition. If you omit the WHERE clause, all the rows in the table will be deleted.
For example, suppose we want to delete the row with id 101 from the customer’s table. We can use the following DELETE statement:

Conclusion:
Data manipulation is an essential skill for working with data in SQL. By using the INSERT, UPDATE, and DELETE statements, you can add, modify, and remove data from tables in a database. These operations are also known as DML (Data Manipulation Language) statements.
If you want to learn more about SQL and Online learning practice and test your SQL skills you can check out here on LearnSQL.com, where you can find interactive courses and exercises on SQL from A to Z.

I hope you found this blog post helpful and informative. If you did, like this post and follow me and as well on LinkedIn for more content on SQL and data analysis. Get my ebook [SQL for Students] on Gumroad for free by leaving a comment below “Send Guide “.
As a final note, I want to share with you a quote that I find inspiring and relevant to the topic of data manipulation:
“Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom.” — Clifford Stoll
Thank you for reading and happy learning!
Comments
Post a Comment