πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      Which SQL command is used to delete all data from a

      table but retain the structure for future use?
      A DELETE Correct Answer Incorrect Answer
      B TRUNCATE Correct Answer Incorrect Answer
      C DROP Correct Answer Incorrect Answer
      D ALTER Correct Answer Incorrect Answer
      E UPDATE Correct Answer Incorrect Answer

      Solution

      The TRUNCATE command in SQL is used to remove all rows from a table, effectively deleting all data while preserving the table's structure for future use. It is often faster than the DELETE command because it bypasses row-level locks and does not generate individual row deletion logs. Instead, TRUNCATE operates at the table level, deallocating data pages and resetting identity columns. TRUNCATE is often used when a clean slate is needed but the table's structure, including its columns, constraints, and indexes, should remain intact. Unlike the DROP command, TRUNCATE does not remove the table itself but merely clears its content. Why Other Options Are Wrong: A) DELETE: The DELETE command removes rows from a table based on a condition but does not reset identity columns or free the storage associated with the rows. C) DROP: The DROP command deletes the entire table, including its structure. It is not suitable when you want to retain the table structure. D) ALTER: The ALTER command is used to modify the structure of a table, such as adding or dropping columns or constraints. It does not delete data. E) UPDATE: The UPDATE command modifies data in a table but does not delete it or clear the table.

      Practice Next

      Relevant for Exams:

      ask-question