2

Which SQL DDL command is analogous to the DML delete command? I think it's truncate but could it be drop?

Randy
  • 51
  • 1
  • 4
  • I'm trying to figure out what your question really means. – Gordon Linoff Oct 05 '15 at 21:47
  • Mureinik is correct. `TRUNCATE` wipes off the data in a table. `DELETE` can do that also, although there are [differences in what happens in the background](http://stackoverflow.com/questions/20559893/comparison-of-truncate-vs-delete-in-mysql-sqlserver). – zedfoxus Oct 05 '15 at 21:52
  • What you are trying to do? – Jean Jung Oct 05 '15 at 21:57

3 Answers3

0

drop [something] removes an object. truncate removes all the rows from a given table. In that sense, you could say it's analogous to a delete operation.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

From MSDN:

DELETE Removes one or more rows from a table or view in SQL Server.

TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources.

Use DROP statements to remove existing entities. For example, use DROP TABLE to remove a table from a database.

Morpheus
  • 1,616
  • 1
  • 21
  • 31
0

TRUNCATE Table used to quickly delete all records in a table and TRUNCATE Never changes the Structure Of a Table while it removes table's data. It removes the spaces that we have allotted to table records.

Drop command is used to flush the table. Drop command is used when we don't need the data.

Jason Clark
  • 1,307
  • 6
  • 26
  • 51
  • Are you certain you want to state that `TRUNCATE TABLE` is DML? Check out [MSDN](https://msdn.microsoft.com/en-us/library/ff848799.aspx?f=255&MSPPError=-2147217396) and [this question](http://dba.stackexchange.com/questions/36607/why-is-truncate-ddl) – Morpheus Oct 08 '15 at 18:27
  • Thanks for the suggestion, I have corrected my mistake. – Jason Clark Oct 10 '15 at 07:06
  • @Morpheus: the SQL standard classifies TRUNCATE as a DML statement. –  Apr 15 '17 at 12:38