July 16, 2013 at 12:36 pm
hi
i need to move data to another table and then remove from old one ,which i needs to delete 30 millions of rows,
i know its taking time but any idea i can do it faster like in a batch
July 16, 2013 at 12:58 pm
You should do it in several batches. If you give us the code you're using, we might be able to help more. A simple example could be this.
SELECT 1
WHILE @@ROWCOUNT > 0
BEGIN
DELETE TOP (1000000)
FROM MyTable
WHERE MyCondition = 'Delete this row'
END
July 16, 2013 at 2:15 pm
If you can, instead just truncate the old table, then re-insert only the kept rows.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
July 16, 2013 at 4:00 pm
copy the table to another table and then truncate the old table
July 16, 2013 at 4:27 pm
Before modifying data it is always a good idea to create a temp table as a backup. Once you delete it all, there's no going back.
July 17, 2013 at 12:54 am
Hi Riya, its better if you keep of your old data in some temp table and then insert the new data....
first insert the old data into a temp table then truncate old table and insert new ones into that....
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 17, 2013 at 1:40 am
riya_dave (7/16/2013)
hii need to move data to another table and then remove from old one ,which i needs to delete 30 millions of rows,
i know its taking time but any idea i can do it faster like in a batch
After deleting 30 million rows from the old table, how many rows are left?
How similar are the two tables?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
July 17, 2013 at 8:19 am
total i have 60 millions rows from there i need to insert 30 millions to some another table.
once it is insert i need to delete it from original table
July 17, 2013 at 8:38 am
riya_dave (7/17/2013)
total i have 60 millions rows from there i need to insert 30 millions to some another table.once it is insert i need to delete it from original table
You can do the delete/insert in the same statement like so:
DELETE TOP (100000) FROM LiveTable
OUTPUT deleted.* INTO ArchiveTable
WHERE ...
--batched up so it doesn't choke up your resources.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply