How do I delete a record from a table in SQL?

Learn SQL with Udemy

For an instructor lead, in-depth look at learning SQL click below.


In this blog post, you will be taken through the process of deleting a record from a table in SQL. SQL, which stands for Structured Query Language, provides a variety of commands to manipulate data stored in a database. One such command is the DELETE statement, which is used to remove existing records from a table.

Basic Syntax for DELETE

The basic syntax for the DELETE statement in SQL is:

This command removes rows of data from a table (“table_name”), based on the condition specified (“some_column = some_value”). The ‘WHERE’ clause is particularly important: if you leave it off, you’ll delete every row from the table.

Example of DELETE Statement

Let’s say we have a table ‘Employees’ with the following data:

And we want to delete the record of the employee with EmployeeId 4. We can achieve that by running the following DELETE statement:

If you now run the SELECT * FROM Employees command again, you would see that employee 4, Emma Stone, has been successfully deleted from our table.

Conclusion

While the DELETE statement is quite useful, it is very powerful and can cause damage to your data if not used carefully. Always ensure that you have properly defined the WHERE condition to avoid deleting wrong or excessive data. Happy Coding!

Leave a Comment