[dba-SQLServer] indexes on cursors

jwcolby jwcolby at colbyconsulting.com
Mon Nov 12 19:17:24 CST 2007


I built a crosstab as follows:

SELECT St as USState, [C] as 'Canoe', [D] as 'Deck', [E] as 'Cat', [H] as
'House', [I] as 'Inflate', [J] as 'JetSki', [M] as 'Muscle', [P] as
'Pontoon',[T] as 'Waterski', [W] as 'Waterski2', [X] as 'Jet'
FROM(
SELECT     dbo.vAZHSIDFamilyHash.St, dbo.vBaseBoatType.Boat_Type
FROM         dbo.vAZHSIDFamilyHash INNER JOIN dbo.vBaseBoatType 
ON dbo.vAZHSIDFamilyHash.PK = dbo.vBaseBoatType.PKID) BoatType
PIVOT 
(
COUNT(BoatType.Boat_Type)
FOR BoatType.Boat_Type IN([C],[D],[E],[H],[I],[J],[M],[P],[T],[W],[X]))
AS BT
ORDER BY USState

Notice the inner select tab is defined as a named cursor BoatType.  The
fields making up the cursor, ST and Boat_Type both have indexes on them.
Will the indexes be used for the outer select in order to perform the actual
count and orderby?

John W. Colby
Colby Consulting
www.ColbyConsulting.com 




More information about the dba-SQLServer mailing list