开发者

Is data copied when selecting into a temp table?

I am wondering, when selecting rows and inserting them into a temp table, is the data actually copied or just referenced?

For example:

SELECT * INTO #Temp FROM SomeTable

If the table is very large, is this going to be a costly operation?

From my tests it seems to execute about as fast as a simple SELECT, but I'd like开发者_JS百科 a better insight about how it actually works.

Cheers.


Temporary tables are allocated in tempdb. SQL server will generally try to keep the tempdb pages in memory, but large tables may end up written out to disk.

And yes, the data is always copied. So, for instance, if an UPDATE occurs on another connection between selecting into your temporary table and a later usage, the temporary table will contain the old value(s)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜