Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Temp Tables

Author  Topic 

Friznost
Starting Member

20 Posts

Posted - 2007-12-05 : 10:39:02
Could someone explain to me the difference between the queries below. I've been told that the later causes the database to lock but I can't find any explanation. Thanks in advance.

CREATE TABLE #TempTbl(Field_1 Varchar(10), Field_2 DateTime)
INSERT INTO #TempTbl
SELECT *
FROM TestTbl


SELECT *
INTO #TempTbl
FROM TestTbl

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-05 : 10:43:52
Second version is fine only when data being fetched from TestTbl is limited. Otherwise, till the time records are being fetched from the TestTbl table, there will be schema lock placed on TempDB.

Also, in case of second version, table constraints and indexes are not copied.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Friznost
Starting Member

20 Posts

Posted - 2007-12-05 : 11:45:28
Thanks for your answer I appreciate it.
Go to Top of Page
   

- Advertisement -