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
 SQL Server Administration (2000)
 what does this mean please ?

Author  Topic 

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2007-01-02 : 05:34:00
Hello the Sql team all the best for the new year to everyone.

I was reading through a interesting article on datawarehouse loading http://www.sqlservercentral.com/columnists/vRainardi/2769.asp when I stumbled across a statement that I have never seen or come acress before :

SELECT * INTO #fact_sales FROM dw.dbo.fact_sales WHERE 1 = 0

could anyone please advise me what this does, does it just create a table schema with no data as 1 will never be = to 0

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2007-01-02 : 05:41:12
quote:
Originally posted by Jim77
SELECT * INTO #fact_sales FROM dw.dbo.fact_sales WHERE 1 = 0




That will create an empty #fact_sales temp table from the existing fact_sales table.



-ec
Go to Top of Page

TonyTheDBA
Posting Yak Master

121 Posts

Posted - 2007-01-02 : 05:41:27
Thats exactly what It does, Creates an empty temporary Table with the same structure as fact_sales. Its a useful trick, when you need to need to have temp tables in code that mirror real tables which could have the structure changed.

--
Regards
Tony The DBA
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-01-02 : 05:48:13
SELECT * INTO #fact_sales FROM dw.dbo.fact_sales

on its own will lock TEMPDB for the duration of the query and insert, not just the Create Table - which can cause contention. So

SELECT * INTO #fact_sales FROM dw.dbo.fact_sales WHERE 1 = 0
INSERT INTO #fact_sales SELECT * FROM dw.dbo.fact_sales

may be better in that regard.

Kristen
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2007-01-02 : 05:58:02
excellent guys that is a cool way to do structural changes on the fly.
Go to Top of Page
   

- Advertisement -