Database Reference
In-Depth Information
Listing 3-4. Column-level statistics: Querying data
select CustomerId, FirstName, LastName, Phone
from dbo.Customers
where FirstName = 'Brian';
select CustomerId, FirstName, LastName, Phone
from dbo.Customers
where FirstName = 'Victor';
Figure 3-4. Column-level statistics: Execution plans
As you can see, SQL Server decides to use a clustered index scan for the first select, which returns 700 rows,
and a nonclustered index scan for the second select, which returns a single row.
Now let's query the sys.stats catalog view and check the table's statistics. The code for this is shown in Listing 3-5.
Listing 3-5. Column-level statistics: Querying sys.stats view
select stats_id, name, auto_created
from sys.stats
where object_id = object_id(N'dbo.Customers')
 
Search WWH ::




Custom Search