it's much faster. But I need to selectively do so.
Is there a way to do this?
Thanks
JihoJiho,
All rows - TRUNCATE TABLE
selective rows - DELETE...WHERE
HTH
Jerry
"Jiho Han" <jhan@.infinityinfo.com> wrote in message
news:a19ab9b12aa9f98c79964e66d0a83@.msnew
s.microsoft.com...
>I need to delete particular rows from a table. I would use TRUNCATE since
>it's much faster. But I need to selectively do so.
> Is there a way to do this?
> Thanks
> Jiho
>|||It's the selective deletion aspect that makes DELETE slower. In addition to
selectively s

for the remaining rows and also log the work as a transaction.
"Jiho Han" <jhan@.infinityinfo.com> wrote in message
news:a19ab9b12aa9f98c79964e66d0a83@.msnew
s.microsoft.com...
>I need to delete particular rows from a table. I would use TRUNCATE since
>it's much faster. But I need to selectively do so.
> Is there a way to do this?
> Thanks
> Jiho
>|||What I was asking and wasn't clear is that I want to delete from table certa
in
rows but not create logs as that seriously slows down the work.
I know TRUNCATE works but for the whole table.
I was wondering if there was a setting or a command that will temporarily
turn off logging or something like that.
Jiho
> Jiho,
> All rows - TRUNCATE TABLE
> selective rows - DELETE...WHERE
> HTH
> Jerry
> "Jiho Han" <jhan@.infinityinfo.com> wrote in message
> news:a19ab9b12aa9f98c79964e66d0a83@.msnew
s.microsoft.com...|||Jiho,
READ ONLY but then you wouldn't be able to perform the DELETE op.
HTH
Jerry
"Jiho Han" <jhan@.infinityinfo.com> wrote in message
news:a19ab9b12aaa658c79969be74d90c@.msnew
s.microsoft.com...
> What I was asking and wasn't clear is that I want to delete from table
> certain rows but not create logs as that seriously slows down the work.
> I know TRUNCATE works but for the whole table.
> I was wondering if there was a setting or a command that will temporarily
> turn off logging or something like that.
> Jiho
>
>|||> What I was asking and wasn't clear is that I want to delete from table
> certain rows but not create logs as that seriously slows down the work.
> I know TRUNCATE works but for the whole table.
> I was wondering if there was a setting or a command that will temporarily
> turn off logging or something like that.
You can't turn logging off. But you may be able to reduce the impact by
temporarily setting the recovery mode to simple or bulk-logged. Be careful
here.|||You can minimize the volume of transaction logging by setting the database
recovery model to "simple". If this is an OLTP database, then remember to
reset back to "full" then you are finished with this large delete operation.
If you are deleting a seriously large number of rows, like > 100,000, then
you may even want to consider dropping indexes before and re-creating them
afterward, since this will reduce transaction logging and maintenance of
indexes during the operation. This is especially true if there is a
clustered index.
Also, when performing a large number of deletes or updates, performance can
be increased by doing so in batches instead of one large operation. By using
rowcount and a while loop, you can limit each operation to a specifed number
of rows.
set rowcount 1000
while
delete from mytable where status = 0
if @.@.rowcount = 0 break
checkpoint
end
"Jiho Han" <jhan@.infinityinfo.com> wrote in message
news:a19ab9b12aaa658c79969be74d90c@.msnew
s.microsoft.com...
> What I was asking and wasn't clear is that I want to delete from table
> certain rows but not create logs as that seriously slows down the work.
> I know TRUNCATE works but for the whole table.
> I was wondering if there was a setting or a command that will temporarily
> turn off logging or something like that.
> Jiho
>
>|||I am reluctant to post this, but...
One of my clients uses the technique of selecting the rows to be kept
into a new table, dropping the old table, renaming the newly created
table, then rebuilding the constraints (if there are any).
There are more things wrong with this approach than I care to
enumerate. I most emphatically recommend you use DELETE... WHERE and
let SQL Server do what it is designed to do - log everything and
rollback if something goes wrong, thereby protecting the integrity of
your data - rather than taking the SELECT.. INTO approach. But
SELECT.. INTO is fast.
Be careful
Payson
Jiho Han wrote:
> I need to delete particular rows from a table. I would use TRUNCATE since
> it's much faster. But I need to selectively do so.
> Is there a way to do this?
> Thanks
> Jiho|||I like the batch recommendation. If you do decided to switch to SIMPLE be
sure to perform a database backup after switching back to FULL (and please
remember to switch back) or atlease a differential to ensure t-log backups
continue to run correctly.
HTH
Jerry
"JT" <someone@.microsoft.com> wrote in message
news:%23BGDKc3yFHA.2008@.TK2MSFTNGP10.phx.gbl...
> You can minimize the volume of transaction logging by setting the database
> recovery model to "simple". If this is an OLTP database, then remember to
> reset back to "full" then you are finished with this large delete
> operation.
> If you are deleting a seriously large number of rows, like > 100,000, then
> you may even want to consider dropping indexes before and re-creating them
> afterward, since this will reduce transaction logging and maintenance of
> indexes during the operation. This is especially true if there is a
> clustered index.
> Also, when performing a large number of deletes or updates, performance
> can be increased by doing so in batches instead of one large operation. By
> using rowcount and a while loop, you can limit each operation to a
> specifed number of rows.
> set rowcount 1000
> while
> delete from mytable where status = 0
> if @.@.rowcount = 0 break
> checkpoint
> end
>
> "Jiho Han" <jhan@.infinityinfo.com> wrote in message
> news:a19ab9b12aaa658c79969be74d90c@.msnew
s.microsoft.com...
>|||> There are more things wrong with this approach than I care to
> enumerate.
For something that is done regularly, I agree.
However, it is a viable approach if you are only interested in keeping, say,
the most recent day's worth of data, and you currently have 6 years' worth.
A