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

那年仲夏 提交于 2019-12-03 23:23:24

问题


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

回答1:


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."




回答2:


It will be removed automatically, as there is nothing left to index. Think of it as a child object in this respect.




回答3:


The drop table will remove the index. Drop Index takes the index name and the table name.

In this case would be DROP INDEX idc ON #tbl

which can be called if you want to drop the index but leave the table.



来源:https://stackoverflow.com/questions/91856/are-indexes-on-temporary-tables-deleted-when-the-table-is-deleted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!