T-SQL – Deletes

There are two ways to delete data from the table.

DELETE FROM [dbo].[TT2_COPY] WHERE id < 1000 -- deletes selected rows
TRUNCATE TABLE [dbo].[TT2_COPY] -- deletes all rows

Delete:
a) is slow,
b) you can remove selected (not all) rows,
c) deletion can be reversed.

Truncate:
a) is faster,
b) deletes all rows, where clause is not supported,
c) cannot be reversed,
d) triggers are not executed,
e) when foreign key references the table it will fail,
f) alter table privilege is neccessary
g) identity is zeroed.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s