Search code examples
sql-serverdbccshrink

Error on sql server database shrink command


I'm executing these commands from a Console Application

DBCC SHRINKFILE (@FILE_NAME_MDF, 0) WITH NO_INFOMSGS
DBCC SHRINKFILE (@FILE_NAME_LDF, 0) WITH NO_INFOMSGS

and getting this error

Could not shrink the XXX database Cannot create a row of size 8126 which is greater than the allowable maximum row size of 8060. The statement has been terminated. System.Data.SqlClient.SqlException (0x80131904): Cannot create a row of size 812 6 which is greater than the allowable maximum row size of 8060.

Any help would be greatly appreciated.


Solution

  • It sounds like your issue here is that a row in your database is near the edge of the maximum allowable size and when the DBCC SHRINKFILE is run, it adds more data to this row and pushes it over the limit. I would look at your tables to see if there is one that is exceeding the size limits and see if you can't change it to store some data off-row. For example, if you have a very large nvarchar field, you could change it to TEXT which will allow you to store that data in its own page.