SQL DELETE command

DELETE command is used to delete row from table. The structure is the following:
DELETE FROM <tableName> WHERE <condition>;
Warning: if we don’t put condition, then it will simply delete all rows in the table.

For example, say we have:


MariaDB [firstDB]> SELECT * FROM employee;
+------------+-----------+-----------------+--------+
| first_name | last_name | employee_number | salary |
+------------+-----------+-----------------+--------+
| Julia      | Roberts   |               1 |  50000 |
| Edison     | Ford      |               2 |  45000 |
| Irina      | Shayk     |               3 |  60000 |
| Yigal      | Arnon     |               4 |  35000 |
+------------+-----------+-----------------+--------+
4 rows in set (0.00 sec)

And we want to delete Irina Shayk, we will do:


MariaDB [firstDB]> DELETE FROM employee WHERE first_name="Irina" and last_name="Shayk";
Query OK, 1 row affected (0.06 sec)

MariaDB [firstDB]> SELECT * FROM employee;
+------------+-----------+-----------------+--------+
| first_name | last_name | employee_number | salary |
+------------+-----------+-----------------+--------+
| Julia      | Roberts   |               1 |  50000 |
| Edison     | Ford      |               2 |  45000 |
| Yigal      | Arnon     |               4 |  35000 |
+------------+-----------+-----------------+--------+
3 rows in set (0.00 sec)

As we can see, one row was deleted, it was the row with Irina Shayk, as first and last name.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s