Showing posts with label valued. Show all posts
Showing posts with label valued. Show all posts

Friday, March 9, 2012

Indexes on table variable of table valued function

Hi there,

Can someone tell me if it is possible to add an index to a Table variable that is declare as part of a table valued function ? I've tried the following but I can't get it to work.

ALTER FUNCTION dbo.fnSearch_GetJobsByOccurrence
(
@.param1 int,
@.param2 int
)
RETURNS @.Result TABLE (resultcol1 int, resultcol2 int)
AS
BEGIN

CREATE INDEX resultcol2_ind ON @.Result

-- do some other stuff

RETURN
ENDhttp://support.microsoft.com/default.aspx?scid=kb;en-us;305977&Product=sql2k

Non-clustered indexes cannot be created on table variables, other than the system indexes that are created for a PRIMARY or UNIQUE constraint.|||Thanks for the reply. That link certainly explains it all.

Also I didn't realise that table variables can be stored on disk if MSSQL deems necessary! Taking everything into account I would think temporary tables are somewhat more useful/versatile!?

Cheers.