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
 Transact-SQL (2005)
 Non clustered index

Author  Topic 

Sachin.Nand

2937 Posts

Posted - 2009-12-24 : 05:28:11
[code]
create table #tbl (name varchar(40))
insert into #tbl
select 'abc' union all
select 'def' union all
select 'mns' union all
select 'xyz'
create nonclustered index IX_name on #tbl(name)
select name from #tbl where name like '[^A-M]%'
select name from #tbl where name like '[A-M]%'

drop index IX_name on #tbl
drop table #tbl
[/code]

The first query is causing Index scan whill second one is causing Index seek.Can anyone throw light on this?

PBUH

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2009-12-24 : 11:33:47
Crazy optimizer... Sometimes you can force a seek...
select name from #tbl where name  like '[A-M]%'
select name from #tbl where name like '[^A-M]%' and name > ''
Go to Top of Page
   

- Advertisement -