Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to drop index on temp table?

Fairly simple question, but I don't see it anywhere else on SO:

Do indexes (indices?) on a temporary table get automatically deleted with the temporary table?

I'd imagine they do but I don't really know how to check to make sure.

Thanks,

Phil

like image 954
Phil Gan Avatar asked May 24 '10 08:05

Phil Gan


Video Answer


1 Answers

Yes they get dropped along with the table. It is not possible for an index to exist independently of its table.

In terms of checking this for yourself you could do

SELECT OBJECT_NAME(OBJECT_ID), * FROM tempdb.sys.indexes

before and after running your DROP temp table.

like image 142
Martin Smith Avatar answered Sep 23 '22 06:09

Martin Smith