SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Delete v Truncate


Delete v Truncate

Author
Message
Error Handler
Error Handler
SSC Eights!
SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)SSC Eights! (800 reputation)

Group: General Forum Members
Points: 800 Visits: 339
Comments posted to this topic are about the item Delete v Truncate

Best,
Naseer Ahmad
SQL Server DBA
demonfox
demonfox
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2119 Visits: 1192
"It" refers to Truncate .
It's a DDL , Data definition language - why ? I think because It resets the identity, that is a database object property change. [because, it does delete so should qualify for DML too ..]

And It doesn't fire trigger , because deletion is actually page deallocations in case of truncate , not individual row deletions .

thanks for the question

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
Dineshbabu
Dineshbabu
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1424 Visits: 569
Thanks for recalling the basics.

Still I have question, why it has been called as DDL command?

--
Dineshbabu
Desire to learn new things..
Danny Ocean
Danny Ocean
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2190 Visits: 1549
Dineshbabu (3/20/2013)
Thanks for recalling the basics.

Still I have question, why it has been called as DDL command?


I think due to different behavior of truncate command, it's consider as DDL Command.
check the below link for more information
http://weblogs.sqlteam.com/mladenp/archive/2007/10/03/SQL-Server-Why-is-TRUNCATE-TABLE-a-DDL-and-not.aspx

But anyway, good question and recall basic again. Good start of day. :-)

Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5154 Visits: 2767
Good basic question...
Thanks Naseer :-)

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
mickyT
mickyT
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2732 Visits: 3318
Thanks for the question.
jpentz99
jpentz99
Old Hand
Old Hand (300 reputation)Old Hand (300 reputation)Old Hand (300 reputation)Old Hand (300 reputation)Old Hand (300 reputation)Old Hand (300 reputation)Old Hand (300 reputation)Old Hand (300 reputation)

Group: General Forum Members
Points: 300 Visits: 315
Interesting - I went with DML, but thinking about it now, it seems more like a hybrid that's both DDL and DML.

Can you fire a DDL trigger when a TRUNCATE TABLE takes place? I don't think it's in the DDL event list.

MS docs sometimes refer to it as a DML operation as well:
"Some data manipulation language (DML) operations, such as table truncation, use Sch-M locks to prevent access to affected tables by concurrent operations." -- http://msdn.microsoft.com/en-us/library/ms175519.aspx

Is there an official list of DDL operations or is its DDL-ness decided by community consensus? :-)
Stuart Davies
Stuart Davies
SSCertifiable
SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)SSCertifiable (7.3K reputation)

Group: General Forum Members
Points: 7277 Visits: 4817
Thanks for the question - good reminder of the basics.
It appears that quite a few here needed reminding of the differences - 40% wrong at the moment.
I wonder how much higher it would have been if you asked which are logged in the question w00t

-------------------------------Posting Data Etiquette - Jeff Moden Smart way to ask a questionThere are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan I would never join a club that would allow me as a member - Groucho Marx
Raghavendra Mudugal
Raghavendra Mudugal
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3298 Visits: 2958
good one. thank you for posting.

I guess it is a long fight because neither way it cannot be proved 100% that it is a DML or DDL depending on the proper action it executes underneath; this link says otherwise http://msdn.microsoft.com/en-us/library/ms175519(v=sql.105).aspx (see under the schema locks section)

(This will be another interesting discussion )

For me it is a DDL (based of my feelings :heheSmile
- it is the quickest way get the data deleted on the single table
- like s/d/u/i statements truncate is not commonly used like others
- in general practice, as truncate removes all the records and no one wants to remove all the records from the table, only if any exceptional case where an SA(sql) or DBA wants to use on some table they think
- in the architecture (generally saying) most of the tables are connected with PK/FK, so again if some one wants to use truncate why would they remove/delete the relationship and then use truncate and then put the relationship back just the sake of deleting?
- as the truncate can be used on single table; so that means that table would be a standalone and it may or may not be storing some kind of data where it is less important like archived log activity of the user stored on a separate table on a different file_group... something like that. (I am not questioning the high standard of the design and how properly each object is configured to use, but just a low point making based on my feelings)

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Raghavendra Mudugal
Raghavendra Mudugal
Hall of Fame
Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)Hall of Fame (3.3K reputation)

Group: General Forum Members
Points: 3298 Visits: 2958
jpentz99 (3/21/2013)
...
MS docs sometimes refer to it as a DML operation as well:
"Some data manipulation language (DML) operations, such as table truncation, use Sch-M locks to prevent access to affected tables by concurrent operations." -- http://msdn.microsoft.com/en-us/library/ms175519.aspx

Is there an official list of DDL operations or is its DDL-ness decided by community consensus? :-)


+1 (i actually posted the same link... reposted by me.... :-D )

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search