As always thanks for attending and for making speaking in Stockholm being a fun thing to do. As promised during the session here are the links to the blog posts I mentioned, the script I used and the slide deck.

SQL Script to for fragmentation on the SQL DB

Checking the database fragmentation:
Use CM_PS1
SELECT DB_NAME(database_id) AS [Database Name], OBJECT_NAME(ps.OBJECT_ID) AS [Object Name], AS [Index Name], ps.index_id, index_type_desc,
    avg_fragmentation_in_percent, fragment_count, page_count
FROM sys.dm_db_index_physical_stats(DB_ID(),NULL, NULL, NULL ,N’LIMITED’) AS ps
    INNER JOIN sys.indexes AS i WITH (NOLOCK)
    ON ps.[object_id] = i.[object_id] AND ps.index_id = i.index_id
WHERE database_id = DB_ID()
AND page_count > 1500
ORDER BY avg_fragmentation_in_percent DESC OPTION (RECOMPILE);