|
|
|
Arguably, the most important factor is achieving optimum performance from SQL Server is the proper construction and maintenance of the indexes. The first task is to determine whether the indexes you will be creating will be used by SQL Server in processing queries. SQL Server will not use an index if the first column of the index is not used either in a search argument of a join clause. The SQL Profiler is a very useful tool in helping to analyze indexes and queries. Indexes are used by SQL Server to enforce uniqueness of data in the database tables and to speed up searches. Creating a useful index is one of the most important tasks in designing a database. It is unprofitable to create indexes on every field in a table, so you must try to choose indexes on fields which are used in joins and search arguments, and which have a high selectivity ratio. The selectivity ratio of an index is calculated by dividing the total unique values in the field by the total number of rows in the table. If the selectivity is high (close to 1), then that field is a good candidate for indexing. Look for ratios higher than .8 to use an index. SQL Server keeps a set of statistics on every index in the sysindexes system table. These are available through the command dbcc SHOW_STATISTICS (tablename, indexname) Stats available are the number of rows in the table and the number of rows sampled. The number of sample values (up to 200), average key length, the index densities (distinct range rows, and average range rows), and sampled value (the endpoint of each range of values) are the other characteristics of stats. Key density is the reciprocal of the count of distinct key values in the tables. The smaller the key density, the more effective the index is likely to be. SQL Server’s query optimizer uses these statistics to determine which indexes to use when executing a query. The index statistics are run when the index is created, or when you update the stats by issuing the command UPDATE STATISTICS table | view [ index | ( statistics_name [ ,...n ] ) ] [ WITH [ [ FULLSCAN ] | SAMPLE number { PERCENT | ROWS } ] | RESAMPLE ] [ [ , ] [ ALL | COLUMNS | INDEX ] [ [ , ] NORECOMPUTE ] ] This updating of index statistics should occur as part of an ongoing program of database maintenance. Recent versions of SQL Server provide for automatic updating of the index statistics table. Another system table counts when rows have been added, deleted or updated in a table. There is another process that monitors those counts, and when certain thresholds are attained, statistics are automatically updated. The SQL Profiler can show when an automatic update is happening. It is also possible to disable the auto update of the statistics table. Index Design Principles• Identify likely indexes by examining the most frequently used queries and transactions ResourcesThis resource provides a general information on SQL. • Tutorial: Introduction to Structured Query Language. This is an excellent resource that discusses SQL in detail. Metro NY / NJ SQL Server ConsultantsWe specialize is custom database software. Call us for a free consultation (973) 635 0080
Computer Consultants: Database Development
|