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 2008 Forums
 Transact-SQL (2008)
 Indexed View help

Author  Topic 

egemen_ates
Yak Posting Veteran

76 Posts

Posted - 2012-06-12 : 03:12:13
my query show belown ; iexamine query plan clusteredIndexScan(viewclustered),how can create nonclustered index for nonclustered index seek.i use which columns for nonclustered index?

SELECT TOP 1

(A+B)

FROM
view_deneme WITH (NOLOCK,noexpand)
WHERE
A_DATE <= {ts '2012-05-31 00:00:00'}
AND M_ID = 14

ORDER BY
A_DATE DESC,
Y_DATE DESC,
K_ID DESC

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-12 : 04:22:59
The date will have to scan - although it can us e an index.
You might get a seek on M_ID but how selective is it?

The order by means that it has to select all the rows and sort them to get the first one so I don't think a seek would be helpful anyway.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-06-12 : 04:47:13
Drop the ODBC style for dates.

WHERE A_DATE < '20120531 00:00:00'



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2012-06-12 : 11:12:50
Could you also post your DDL with the existing index definitions with some test data?

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -