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.
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 = 0could 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 Jim77SELECT * 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 |
 |
|
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.-- RegardsTony The DBA |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-01-02 : 05:48:13
|
SELECT * INTO #fact_sales FROM dw.dbo.fact_saleson its own will lock TEMPDB for the duration of the query and insert, not just the Create Table - which can cause contention. SoSELECT * INTO #fact_sales FROM dw.dbo.fact_sales WHERE 1 = 0INSERT INTO #fact_sales SELECT * FROM dw.dbo.fact_salesmay be better in that regard.Kristen |
 |
|
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. |
 |
|
|
|
|