Click here to Skip to main content
15,886,562 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone, I created two B-tree indexes in the popular employees database and I want to write sql queries to show some limitations of these indexes. The query I have below can't prove anything using one of the indexes that I created. Please can anyone show me a query that can show some limitations of these indexes ? Thanks for any help.

What I have tried:

use employees;

CREATE INDEX indx_emp on employees(emp_no);

CREATE INDEX indx_gen on employees(gender);

SELECT 
    *
FROM
    employees USE INDEX (INDX_EMP)
WHERE
    emp_no BETWEEN 10980 AND 100000
        AND gender = 'M'
ORDER BY birth_date;
Posted
Updated 6-Apr-21 22:05pm
Comments
CHill60 6-Apr-21 9:39am    
What do you mean by the "limitations of these indexes"?
UT7 6-Apr-21 22:55pm    
I want to show situations where this index would be ineffective searching the database. Thanks.
[no name] 6-Apr-21 15:45pm    
There is no "USE INDEX" option.
UT7 6-Apr-21 22:57pm    
"USE INDEX" is there, please check. Thanks.

1 solution

You appear to be trying to use the "USE INDEX Hint" and noting the relative effects of various indexes.

These blogs from Pinal Dave will give you an introduction:
SQL SERVER - Introduction to Force Index Query Hints - Index Hint - SQL Authority with Pinal Dave[^]
SQL SERVER - Introduction to Force Index Query Hints - Index Hint - Part2 - SQL Authority with Pinal Dave[^]

There are some articles here on Code Project about using the SQL Profiler - you will need something like this to compare the results
SQL Server Profiler Step by Step[^]
MS SQL Server Profiler with .NET[^]

This one is now unfortunately out of date and no longer kept up to date, but probably still worth a read - Tools of the Trade: SQL Server Profiler and Query Analyzer | Microsoft Docs[^]
 
Share this answer
 
Comments
UT7 7-Apr-21 4:12am    
Wow, thanks a lot. I'll read the articles, thanks.
UT7 24-Apr-21 21:48pm    
@CHill60, those articles are very good, it didn't solve my issue directly but it is very helpful. Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900