Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating empty table using SELECT...INTO 1

Status
Not open for further replies.

NathanGriffiths

Programmer
May 14, 2001
213
0
0
NZ
The BOL help for SELECT tells me:

"You can use SELECT...INTO to create an identical table definition (different table name) with no data by having a FALSE condition in the WHERE clause."

but can anyone tell me what the actual syntax for a statement like this would be?

thanks,

Nathan
 
I think it goes something like this

select sourcetable.* into newtablename
from sourcetable
where sourcetable.field ='non-matching criteria'

Andy
 
Try some of the following.

WHERE 3 < 2

WHERE 0 = 1

THESE WORK IN DB2. I haven't tried them in SQL SERVER.
 
Hi, just put a condition that will never be true in the where clause. For example, i have a table (tb_users) with a cd_user column. I know that every user has a cd_user code greater than 0, so i can replicate my structure with this transact-sql:

select * into tb_users2 from tb_users where cd_user=0

The tb_users 2 will be created with no records.

Sergio M. Netto.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top