Of Code and Me

Somewhere to write down all the stuff I'm going to forget and then need

Find the level of index fragmentation in a Sql Server database December 4, 2009

Filed under: Sql Server,Systems Administration — Rupert Bates @ 11:48 am

This will return the level of fragmentation for every index in the current database:

SELECT b.NAME, [a].*
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL,
     NULL, NULL, NULL) AS a
     JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id
WHERE [a].index_id <> 0
ORDER BY avg_fragmentation_in_percent desc
 

SQL Server 2005 error: Database diagram support objects cannot be installed because this database does not have a valid owner April 17, 2009

Filed under: Error,Sql Server,Uncategorized — Rupert Bates @ 10:19 am
Tags:

With SQL Server 2005, when you get the error message:

“Database diagram support objects cannot be installed because this database does not have a valid owner.  To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.”

Even when the database does have a valid owner, then the database compatibility level is probably set to lower than 90, this can happen if you restore a database created in an earlier version of SQL Server. To fix it run:

sp_dbcmptlevel @dbname=’MyDatabaseName’, @new_cmptlevel=90