This article explains how to reduce database size before or after newer TRBOnet version install and before Database upgrade attempt.
Before new version install
After new version install without Database upgrade attempt
Step 1: Check Database State
Step 2: Stop TRBOnet Service
Step 3: Identify Large Tables
Before making changes, check which tables use the most space.
GO
sp_msforeachtable N'EXEC sp_spaceused [?]';
GO
This script shows the size of each table, including related objects such as indexes.
Step 4: Rebuild Indexes
Step 5: Shrink the Database
After rebuilding indexes, SQL Server still reserves space based on previous data size.
To reclaim unused space, shrink the database:
Step 6: Delete Old Data
sp_ClearOldData instead of a standard DELETE statement.
Example for the table with GPS data :
EXEC @return_value = [dbo].[sp_ClearOldData]
@tableName = N'GpsInfo',
@dateColumnName = N'date',
@date = '2022-11-07 00:00'
This procedure processes data in batches using multiple transactions. It reduces transaction log growth and usually performs better than a standard DELETE.
The procedure deletes all records older than the specified date, starting from the oldest records. Make sure the date is correct before running the script.
WHERE [date] < '2022-11-07 00:00 +03:00'
Step 7: Shrink the Database
After deleting old data, perform another database shrink to reclaim the freed space.