Databases Reference
In-Depth Information
Query Selectivity:
Query Selectivity is represented by the number generated by:
Total number of distinct value in the column / Total number of value in the column
For example, one table with two fields, ID and Name, has a total of 1,000,000 records
and has 900,000 unique names in the Name column. Thus, the selectivity of the column
would be:
900,000 / 1,000,000 = 0.9
A higher selectivity always improves the performance of an index, and that is why the ideal
selectivity is 1, which can be achieved by using Primary Key or a unique key.
Creating and updating statistics
Statistics is an integral part of performance as it helps the SQL Server optimizer choose the
proper operation to be performed while executing the SELECT statement. There are two main
ways to create and update statistics:
F Manually create/update statistics
F Automatically create/update statistics
We will see these options in this recipe.
Getting ready
Before we move further to generate statistics, let us see some commands to view the current
settings of statistics for database and table.
The following script will let you know whether the Auto_Create_Statistics option is
enabled for databases or not:
SELECT
CASE
WHEN
DATABASEPROPERTYEX('Master','IsAutoCreateStatistics')=1
THEN
'Yes'
ELSE
'No'
END as 'IsAutoCreateStatisticsOn?',
CASE
WHEN
DATABASEPROPERTYEX('Master','IsAutoUpdateStatistics')=1
THEN
 
Search WWH ::




Custom Search