Sql-server – Finding integer database columns that may have their data type changed to reduce size

database-sizesql server

I have a database schema that I've inherited where all the integer columns have been defined as int but because of business rules many could be replaced by tinyiny and other data types that would require less storage. While I don't expect much of a performance improvement by using the smaller types my reasons for wanting to do so are:

  • The application uses SQL Server Express so I'd like to make the most of the 10GB database size before needing to purge data.

  • The application is shipped with a full initial copy of the database and updates are synced using the Microsoft Sync Framework. Some client PCs are on relatively slow Internet connections so the smaller the database size the better.

I was wondering if there was some way to quickly identify columns that may be 'oversized'? I realize that the results will need to be carefully reviewed to make sure that the column will never exceed the limits of the new data type.

Best Answer

You might be able to save yourself a lot of work if you can upgrade to SQL Server 2016 SP1 or later. Data compression is available even in Express edition starting with that service pack. You could simply apply row compression to all tables and indexes to save even more space than what you can get from changing data types. That's because the data types that you mention only use bytes needed to fit the actual values with row compression. Screenshot from the documentation:

enter image description here