What is a difference between DROP TABLE and TRUNCATE TABLE and DELETE FROM?
Experience Level: Medior
Tags: Databases
Answer
Answer
- DROP TABLE - removes the table structure and data.
- TRUNCATE TABLE - removes all data from table but preserves the structure so the table can be used later. The operation cannot be used on tables that have foreign keys. It's ultra fast as it's minimally logged, so it uses less transaction log space. Fewer locks are typically used. After successful executions, zero rows are left in the table.
- DELETE FROM - removes data matching criteria from table. It's slower than TRUNCATE TABLE, but it can be used for removing just couple of rows, not eveything.
Related Databases job interview questions
What is SSMS?
DatabasesQuality Assurance (QA) JuniorWhat is Microsoft SQL Server Management Studio and what is it good for?
DatabasesQuality Assurance (QA) JuniorWhat will be the result of the following T-SQL?
Code challengeDatabasesMS SQL ServerSQL SeniorWhat is the difference between OLAP and OLTP? When is each used?
Databases MediorDescribe the difference between optimistic and pessimistic locking.
Databases Medior