Shrinking DB Cause Increase In Fragmentation
Let's understand how shrinking Database can increase Index fregmentation. When the DB is shrunk, the sql server db engine goes at the end of the data pages located in the database and adjust them in the size mentioned for shrink activity. This is the reason why shrink causes data pages unorganized and result in fragmentation. Let's create a database name CitiesPopulation. and some tables like EMployeeInfo EmployeeInfo1 EmployeeInfo2 PopulationInCaror Get the DBId from the output of below query- select * from sys.sysdatabases For my database CitiesPopulation, the DBid is 7. Now check for the index fregmentation status in your Database with the help of below query- SELECT * FROM sys.dm_db_index_physical_stats(7, null, null, null, null) You can also check the fregmentation for a perticular table by giving the object_Id in the above query e.g. SELECT * FROM sys.dm_db_index_physical_stats(7, OBJECT_ID('Employeeinfo'), null, null, null