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)
 Help with Understanding this

Author  Topic 

dturner
Starting Member

24 Posts

Posted - 2006-09-07 : 15:36:16


Select * into table
from mytable
Where (1 = 0)

I am not sure what this is actually doing "Where (1 = 0)"

The world has more information to offer than I can hold in my head

Gopi Nath Muluka
Starting Member

22 Posts

Posted - 2006-09-07 : 15:46:04
The Query you specified will create a table1 same like mytable but It doesn't insert any rows into the table
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-09-07 : 15:48:33
Select * into table from mytable builds the table and copies the rows. Adding the WHERE clause just builds the table.

Tara Kizer
Go to Top of Page

dturner
Starting Member

24 Posts

Posted - 2006-09-07 : 16:13:25
I see, so really it is creating a table that is the same as another table.

The world has more information to offer than I can hold in my head
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-09-07 : 16:16:02
Yes but without the data. The WHERE part is crucial if you don't want the data as well.

Tara Kizer
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-09-07 : 16:23:29
The point is that
WHERE (1 = 0)
is just a WHERE clause that returns no rows because its expression evaluates to false. There is nothing special in the expression 1 = 0, its just something simple that evaluates to false - it could be anything (5 = 6, '' = 'a' etc.).
Go to Top of Page

dturner
Starting Member

24 Posts

Posted - 2006-09-07 : 16:53:26
Ok, I see that so if I use WHERE (1=1) it would copy the table with all data correct.

Thank you all

The world has more information to offer than I can hold in my head
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-09-07 : 16:56:01
If you want all of the data, then just use this:

SELECT *
INTO NewTableName
FROM YourTableName

Don't use a WHERE clause if you want all of the data.

Tara Kizer
Go to Top of Page
   

- Advertisement -