Ad
Sponsored by Sir Tauqeer
CLICK HERE TO JOIN SIR TAUQUEER WHATSAPP GROUP
FOR PREPARATION CLASSES AND JOBS UPDATES
Join Now

Which SQL command is used to delete all records from a table without deleting the table structure?

A. DROP
B. TRUNCATE
C. DELETE
D. REMOVE
Correct Answer: B. TRUNCATE

The SQL command used to delete all records from a table without deleting the table structure is TRUNCATE. While DELETE can also remove all rows, TRUNCATE TABLE is generally faster and more resource-efficient for this specific task, especially on large tables.

Here's a breakdown of why:

  • TRUNCATE: This command deallocates the data pages used by the table and logs only the deallocation of these pages. It's a DDL (Data Definition Language) command, meaning it's non-transactional and cannot be rolled back in most database systems. It effectively resets the table to its initial empty state, often resetting identity columns as well.
  • DELETE: This is a DML (Data Manipulation Language) command. When used without a WHERE clause, it removes all rows one by one, logging each deletion. This makes it slower but allows for rollback.
  • DROP: This command completely removes the table definition and all its data from the database.
  • REMOVE: This is not a standard SQL command for deleting records.

Therefore, for a quick and efficient removal of all data while preserving the table's schema, TRUNCATE TABLE is the preferred choice.

Leave a Comment

Join Our WhatsApp Channel ×
Scroll to Top