Vikas Rajput
Vikas Rajput

@vikasrajputin

9 تغريدة Dec 06, 2022
SQL: DELETE, TRUNCATE and DROP commands
🧵👇
1. DELETE
- It supports the where clause in the query, so conditionally we can remove selected rows from a table.
- When not using the where clause it removes all rows from the table.
- Auto increment values of the primary key start from the previous number.
- It only removes data from the table and keeps the structure as is.
Eg:
- Given an EMPLOYEE table, now delete query can be written as shown below:
2. TRUNCATE
- In TRUNCATE, we've no option to use the where clause due to which it will remove all the rows from the table.
- After TRUNCATE, if we insert a new record in the table then AUTO INCREMENT primary key values normally start from the beginning.
- It only removes data from the table and keeps the structure as is.
Eg:
- Given an EMPLOYEE table, the TRUNCATE query looks like as below:
3. DROP
- The DROP query, removes the whole object in the database.
- It can be used to remove the entire table structure along with its data.
- Similarly, it can be used to remove Stored procedures, Functions, Triggers, Index, Constraints, etc.
Eg:
- Given as EMPLOYEE table, DROP will look like as below:
That's a wrap!
If you loved reading this thread, you might enjoy reading my previous thread on SQL:
Namaste, I'm Vikas!
Trying to diversify tech twitter with Backend content.
Every Mon, Wed & Fri - I write a thread,
follow @vikasrajputin to read all my future threads.

جاري تحميل الاقتراحات...