« Es ist wohl so :-) | Main| Octave .... »

Lange nix geschrieben, hier eine Kleinigkeit zum Wiedereinstieg

8
Kategorie
Was ist eigentlich der Unterschied zwischen einem TRUNCATE und einem DELETE?
ungefähr dies ->



The difference in TRUNCATE and DELETE in Sql Server

I’ve answered this question many times, and answered it again this weekend.  What is the difference when doing a DELETE TableA instead of TRUNCATE TableA?  A common misconception is that they do the same thing.  Not so.  In fact, there are many differences between the two.

DELETE is a logged operation on a per row basis.  This means that the deletion of each row gets logged and physically deleted.

You can DELETE any row that will not violate a constraint, while leaving the foreign key or any other contraint in place.

TRUNCATE is also a logged operation, but in a different way.  TRUNCATE logs the deallocation of the data pages in which the data exists.  The deallocation of data pages means that your data rows still actually exist in the data pages, but the extents have been marked as empty for reuse.  This is what makes TRUNCATE a faster operation to perform over DELETE.

You cannot TRUNCATE a table that has any foreign key constraints.  You will have to remove the contraints, TRUNCATE the table, and reapply the contraints.

TRUNCATE will reset any identity columns to the default seed value.  This means if you have a table with an identity column and you have 264 rows with a seed value of 1, your last record will have the value 264 (assuming you started with value 1) in its identity columns.  After TRUNCATEing your table, when you insert a new record into the empty table, the identity column will have a value of 1.  DELETE will not do this.  In the same scenario, if you DELETEd your rows, when inserting a new row into the empty table, the identity column will have a value of 265.





Gefunden -> hier

Gruß JJR
P.S.: Vielleicht demnächst ein wenig mehr zu ENTERPRISE!

Kommentare

Gravatar Image1 - Hallo Jörg,

interessant ist der kleine aber feine Zusatz mit den Identity-Columns: da sollte man sich schon im klaren drüber sein, dass die bei Truncate zurückgesetzt werden und ob man das überhaupt will... wusste ich vorher nicht.
Obwohl es solche Spalten ja in einer richtigen DB sowieso nicht gibt... Emoticon

Gruß,
Sebastian

P.S.: jaaaaa, wir wollen was über ENTERPRISE hören! Emoticon

Gravatar Image2 - Hallo Sebastian,

ich gebe Dir vollkommen recht, dass in einer Datenbank, solche Spalten nicht vorkommen sollten Emoticon Und über "Enterprise" wirst Du bestimmt, was zu Lesen bekommen Emoticon

Gruß JJR

Mach einen Kommentar

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Amazon


Impressum

Firmenname: Peanuts-Soft
Straße Nummer: Biinger Strasse 8
PLZ Ort: 55263 Wackernheim
Telefon: +491772134526
E-Mail: joerg.reck @ peanuts-soft.de
Disclaimer: Peanuts-Soft übernimmt keine Garantie dafür, dass die auf dieser Website bereitgestellten Informationen vollständig, richtig und stets aktuell sind. Dies gilt auch für alle Links, auf die verwiesen wird. Peanuts-Soft ist für die Inhalte, auf die per Link verwiesen wird, nicht verantwortlich. Peanuts-Soft haftet nicht für konkrete, mittelbare und unmittelbare Schäden oder Schäden, die durch fehlende Nutzungsmöglichkeiten, Datenverluste oder entgangene Gewinne – sei es aufgrund der Nichteinhaltung vertraglicher Verpflichtungen, durch Fahrlässigkeit oder eine andere unerlaubte Handlung – im Zusammenhang mit der Nutzung von Dokumenten oder Informationen bzw. der Erbringung von Dienstleistungen entstehen, die auf dieser Web Site zugänglich sind.
Datenschutz: Inhalt und Gestaltung der Internetseiten sind urheberrechtlich geschützt. Eine Vervielfältigung der Seiten oder deren Inhalte bedarf der vorherigen schriftlichen Zustimmung von Peanuts-Soft.


Locations of visitors to this page

Powered By

Domino BlogSphere
Version 3.0.2