I am creating temp tables (#temp_table
) in my stored procedure. It is a huge table with large data. Then I am creating a index in the storeed procedure as it is required for faster query to the temp table. But when I execute the stored procedure, the index is not used. The index is not being created when the stored procedure is executed.
Pseudo code
CREATE PROC abcdefg
AS
...
SELECT col_a, col_b, col_c....
INTO #temp_table
FROM .....
WHERE ....
...
CREATE INDEX abc_idx ON #temp_table (col_a)
...
SELECT col_a FROM #temp_table WITH (INDEX (abc_idx))
...
GO
When I try to execute the stored proc, it is not recognizing the index. How can I fix this problem?