DEV Community

Cover image for Most Frequently Asked SQL question in Interviews - freest_man
Knowledge From Twitter
Knowledge From Twitter

Posted on • Updated on • Originally published at infotweets.com

Most Frequently Asked SQL question in Interviews - freest_man

Original Tweet From @freest_man


I went through SQL 156 question bank and sat for 5 interviews

Here is the most frequently asked

What is the difference between DELETE, DROP and TRUNCATE?

Take a moment to think of the possible answer before continuing

1/ DELETE

It is a Data Manipulation Language (DML) command.

It can delete all rows or certain rows under conditions using WHERE. Twitter Image 0

DELETE cannot delete the structure of the table.

ie The column names still exist but with empty rows.

We can restore the deleted rows using the ROLLBACK command.
AdSpace Here!!

2/ DROP

It is a Data Definition Language (DDL) command.

With the help of DROP it can delete the entire table along with its structure. Twitter Image 1

ROLLBACK command cannot restore the dropped table.

By using DROP the existence of the whole table is gone.
AdSpace Here!!

3/ TRUNCATE

It is also a Data Definition Language (DDL) command.

TRUNCATE can only delete all the rows from the table in one go. Twitter Image 2

It cannot be used with the WHERE command.

It is faster than the DELETE command.

Here we cant restore the values using ROLLBACK.

That's a wrap!
AdSpace Here!!
If you enjoyed this thread:

  1. Follow me @freest_man for more of these
  2. RT the tweet below to share this thread with your audience https://twitter.com/1562857893958823936/status/1591075118389657601

Click Here For More Posts Like This https://www.knowledge-twitter.com

Top comments (0)