Are indexes on temporary tables deleted when the table is deleted?

Manu picture Manu · Sep 18, 2008 · Viewed 16.5k times · Source

Would the following SQL remove also the index - or does it have to be removed separately?

CREATE TABLE #Tbl (field int)

CREATE NONCLUSTERED INDEX idx ON #Tbl (field)

DROP TABLE #Tbl

Answer

sdkpoly picture sdkpoly · Sep 18, 2008

Yes they are. You can search in MSSQL help for CREATE INDEX article it is said there:

"Indexes can be created on a temporary table. When the table is dropped or the session ends, all indexes and triggers are dropped."