Have you ever wanted to find out how big certain tables in your ConnectWise database are?
Here is a simple script to show you the top tables in your database, and as well as their true size.
This script does several things:
- The first part is a handy function that pretties up a lot of the ConnectWise table names. Table names in their raw form in the DB are not as easy to read, so this puts the most common table names into an easy-to-read format. The function is dropped at the end of the script, but feel free to leave it in your DB if you find it useful for other purposes.
- The second part of the script uses some of SQL Server's built-in functions to count the size of a database and collate it for you. First, it will spit out the overall size of your database and then it will show the top 25 tables with their row numbers and sizes.
Script to Reveal Table Size in ConnectWise
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
USE [cwwebapp_site] CREATE FUNCTION [dbo].[CleanCWTableName] ( @tablename VARCHAR(100) ) RETURNS VARCHAR(100) AS BEGIN DECLARE @ret VARCHAR(100); SET @ret = REPLACE(@tablename, 'DM_', 'Document-'); SET @ret = REPLACE(@ret, 'AGR_', 'Agreement-'); SET @ret = REPLACE(@ret, 'BL_', 'Billing-'); SET @ret = REPLACE(@ret, 'SO_', 'Opportunity-'); SET @ret = REPLACE(@ret, 'SR_', 'Service-'); SET @ret = REPLACE(@ret, 'PM_', 'Project-'); SET @ret = REPLACE(@ret, 'IV_', 'Inventory-'); SET @ret = REPLACE(@ret, 'SRT_', 'Task-'); SET @ret = REPLACE(@ret, 'EX_', 'Expense-'); SET @ret = REPLACE(@ret, 'SV_', 'Configuration-'); SET @ret = REPLACE(@ret, 'TE_', 'Time Entry-'); SET @ret = REPLACE(@ret, 'WF_', 'Workflow-'); SET @ret = REPLACE(@ret, 'KB_', 'Knoweledge Base-'); SET @ret = REPLACE(@ret, '_', ' '); RETURN @ret; END GO SET NOCOUNT ON EXEC sp_spaceused; -- Table row counts and sizes. DECLARE @tablesize TABLE ( [name] NVARCHAR(128), [ROWS] CHAR(11), reserved VARCHAR(18), DATA VARCHAR(18), index_size VARCHAR(18), unused VARCHAR(18) ) INSERT @tablesize EXEC sp_msForEachTable 'EXEC sp_spaceused ''?''' SELECT top 25 [dbo].[CleanCWTableName](name) AS [TABLE FUNCTION], name AS[TABLE Name], CAST(ROWS AS INT) ROWS, CAST(REPLACE(reserved,' KB','') AS INT)/1024 AS SizeMB FROM @tablesize ORDER BY SizeMB DESC DROP FUNCTION [dbo].[CleanCWTableName];
Hey, I only see X many tickets in my ConnectWise UI. Why does the table have so many more?
There could be several reasons for this discrepancy. Project tickets and service tickets use the same table. Your user could only have access to certain tables in the ConnectWise UI. Or there could be some old tickets in the database that are not visible in the UI.
Are none of these the scripts you're looking for? Check out all the other ways we can help you manage your ConnectWise database.