Delete Large amount of Records

RosOmar
Member Posts: 7
Ladies and Gents,
Due to some wrong functional setup and programming, one of our clients now has a table with 2bln lines which takes upto 2tb of storage. The table data is not being used anywhere anymore.....;)
I have been trying to delete these through processing reports and codeunits, with deleteall. This does not work (ie takes too long and/or sql error).
Online I have seen someone mention following:
"Object.SETRANGE(Type,Object.Type::TableData);
Object.SETRANGE("Company Name",COMPANYNAME);
Object.SETRANGE(ID,DATABASE::"Customer Price Group"); // This is the table to flush
Object.DELETEALL;"
Would appreciate your opinion or a proposed solution.
Thanks in advance.
Due to some wrong functional setup and programming, one of our clients now has a table with 2bln lines which takes upto 2tb of storage. The table data is not being used anywhere anymore.....;)
I have been trying to delete these through processing reports and codeunits, with deleteall. This does not work (ie takes too long and/or sql error).
Online I have seen someone mention following:
"Object.SETRANGE(Type,Object.Type::TableData);
Object.SETRANGE("Company Name",COMPANYNAME);
Object.SETRANGE(ID,DATABASE::"Customer Price Group"); // This is the table to flush
Object.DELETEALL;"
Would appreciate your opinion or a proposed solution.
Thanks in advance.
0
Best Answers
-
Truncate should work...
Just ensure that database is on single user for it to be faster.
0
Answers
-
Running that "Object" code would be a VERY BAD idea.There are no bugs - only undocumented features.0
-
Find a way to split it up into smaller chunks and do a COMMIT in between chunks. Maybe there's a field with a foreign key that you can filter on. For instance, if I were to delete 2 bln Item Ledger Entries, I would probably run it per Item, per Location, and per month on the posting date.1
-
Truncate should work...
Just ensure that database is on single user for it to be faster.
0 -
Gents,
Thank you very much! Truncate Table from Server Management Studio worked like a charm. All data GONE within a second.0 -
For a truncate to be faster, you don't need the database in single user. truncate is logged in the transaction log in SQL Server, but unlike deleteall which logs ALL single records in the transaction log, truncate logs only the truncate command. Truncate on a table has also as side-effect, that it resets the autoincrement on the field in that table (if there is an autoincrement field on that table). truncate on a table should only take a few seconds.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!1 -
Truncate doesn't actually delete anything. It simply reallocates the space in the database. That is why it is so quick. It's similar to "deleting" a file from Windows. All that happens is to reallocate the space and remove the directory entry. That's why "Recovery Bin" works.
There are no bugs - only undocumented features.0 -
I also go on SQL for these requirements.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions