Are you

SQL DELETE TABLE


To delete rows from a table, use the DELETE statement. You should use the WHERE condition to remove a specific row from a table.

DELETE FROM table_name [WHERE condition];

However, if you don't include a WHERE condition, the table will be stripped of all rows.

DELETE FROM table_name;

There are also other terms that are similar to the DELETE statement, such as DROP and TRUNCATE, but they are not identical and have some variances.

What are the difference between DELETE and TRUNCATE statements?

There is a little distinction between the delete and truncate statements. The DELETE statement only deletes rows from the table that meet the WHERE clause's condition, or it deletes all rows from the table if no condition is supplied. But it does not free the space containing by the table.

The TRUNCATE statement: it is used to delete all the rows from the table and free the containing space.

What are the Difference between DROP and TRUNCATE statements?

When you use the drop statement, it deletes the table's row as well as the table's definition, making all of the table's associations with other tables invalid.

When you drop a table:

  • Table structure will be dropped
  • Relationship will be dropped
  • Integrity constraints will be dropped
  • Access privileges will also be dropped

When we TRUNCATE a table, on the other hand, the table structure remains unchanged, so none of the above issues arise.

SQL DELETE ROW

Let us take an example of student table.

Original table:

IDSTUDENT _NAMEADDRESS
001JohnKigali
002ClaudeNyagatare
003BenoitKigali

The SQL DELETE query for deleting a student with id 003 from the student_name table should look like this:

DELETE FROM student_name WHERE id = 003;

Resulting table after SQL DELETE query:

IDSTUDENT_NAMEADDRESS
001JohnKigali
002ClaudeNyagatare
Next

Courses