Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Analyse and create new Indexes

Author  Topic 

sql_server_dba
Posting Yak Master

167 Posts

Posted - 2010-12-07 : 22:25:58
Hi All,

I would really appreciate if someone can help me on how to get this started. Here is the situation...
I have a database which has around 80 tables. This is the datamart which extracts data from some other database and the data init is repository, so we do not have any primary keys or foreign keys. But we do have clustered and non-clustered indexes. So now, i have to analyse which tables does not have a clustered index and need to create them but i am unable to figure out where to begin with. Any kind of help is highly appreciated.

Thanks in Advance

denis_the_thief
Aged Yak Warrior

596 Posts

Posted - 2010-12-08 : 15:41:46
This may help. Link:

http://www.sql-server-performance.com/articles/per/Identify_Missing_Indexes_Using_SQL_Server_DMVs_p1.aspx

A Query:

SELECT DB_NAME(d.database_id) AS DBNAME,
d.statement AS [ObjectName], equality_columns, inequality_columns, included_columns,
gs.unique_compiles,
gs.user_seeks,
gs.user_scans,
gs.avg_total_user_cost,
gs.avg_user_impact,
'CREATE INDEX MissingIndex_' + rtrim(cast(d.index_handle AS char(100))) +
' ON ' + d.statement + ' (' +
CASE WHEN equality_columns IS NOT NULL THEN equality_columns ELSE '' END +
CASE WHEN equality_columns IS NOT NULL AND
inequality_columns IS NOT NULL THEN ', ' ELSE '' END +
CASE WHEN inequality_columns IS NOT NULL THEN inequality_columns ELSE '' END + ') ' +
CASE WHEN included_columns IS NOT NULL THEN 'INCLUDE (' + included_columns + ')' ELSE '' END AS MissingIndex
FROM sys.dm_db_missing_index_groups g
join sys.dm_db_missing_index_group_stats gs ON gs.group_handle = g.index_group_handle
join sys.dm_db_missing_index_details d ON g.index_handle = d.index_handle
WHERE DB_NAME(d.database_id) = '[PUT YOUR DATABASE NAME HERE]'
ORDER BY gs.avg_total_user_cost DESC;
Go to Top of Page

sql_server_dba
Posting Yak Master

167 Posts

Posted - 2010-12-09 : 01:59:54
Nice article. It gave me some idea to proceed.

Thanks
Go to Top of Page
   

- Advertisement -