3

Upon reviewing some of our code a colleague posited that he was annoyed at always having to write TRUNCATE TABLE when there is no real other usage for TRUNCATE.

Googling this, I indeed can not find a specific reason why the TABLE part is needed.
What am I missing? Is there some historical reason for the TABLE in TRUNCATE TABLE?

2
  • 1
    It's probably because SQL is supposed to look like text. On the other hand I'd like to have a TRUNCATE PARTITION/FILEGROUP/DATABASE feature. It's an extensibility point for the language.
    – usr
    Commented May 22, 2015 at 11:18
  • @usr the first one is possible in 2016 msdn.microsoft.com/en-us/library/ms177570(v=sql.130).aspx Commented May 27, 2015 at 23:10

2 Answers 2

8

The syntax choice is likely for consistency, albeit redundant. TRUNCATE TABLE follows the same pattern as other DDL statements (CREATE, ALTER, DROP), where the object type immediately follows the action keyword.

I should add TRUNCATE TABLE is part of the ANSI SQL Standard as of the 2008 version, although it was implemented in SQL Server long before then.

3

Seems to me its redundancy for future extensibility. There may not be any other use for TRUNCATE currently, but one could be added in the future. Or at least that would have been the mindset of the developers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.