#Temporary views and functions return errors stating they're not allowed.
Use Text-only results, and include the execution plan to see the index has been used.
Q&A about the site for people who love being outdoors enjoying nature and wilderness, and learning about the required skills and equipment
-- #Temporary tables, indexes and procedures work!
-- #Temporary views and functions do not.
-- Use Text-only results, and include the execution plan to see the index has been used.
CREATE TABLE #Test (id int IDENTITY(1,1) NOT NULL, v VARCHAR(MAX) NOT NULL);
CREATE INDEX #IX_T on #Test(id)
-- CREATE VIEW #V_T AS SELECT v FROM #Test
CREATE PROCEDURE #T_P AS
-- CREATE FUNCTION #G_D() RETURNS DATETIME AS
-- RETURN GETDATE()
CREATE PROCEDURE #T_P2 @v VARCHAR(MAX) AS
INSERT INTO #Test(v) SELECT @@VERSION;
INSERT INTO #Test(v) VALUES ('Yay!');
SELECT * FROM #Test ORDER BY id;