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
 General SQL Server Forums
 New to SQL Server Programming
 creating table with a select statement

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2006-11-27 : 00:11:43
Dear folks,

create table temptable(eno, ename) as select eno, ename from emp.

here the problem is it is asking for the datatype for the temporary table.

is it not possible to create the temp table without providing the datatypes?

thank you very much.

Vinod

shaggy
Posting Yak Master

248 Posts

Posted - 2006-11-27 : 00:39:52
for creating table u have to mention datatype.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-27 : 00:52:20
[code]select eno, ename into temptable from emp[/code]



KH

Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2006-11-27 : 00:58:19
Thank you KH

Vinod
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-27 : 07:18:19
Note that the target table wont have indices, constraints, etc that source table has

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-27 : 08:11:53
And if you want to create an empty temp table, just add a nonsense WHERE to it.

select eno, ename into temptable from emp where 1 = 0


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-11-27 : 08:19:27
"Note that the target table wont have indices, constraints, etc that source table has"

But any IDENTITY attribute will be preserved - which can be a nuisance - particularly if you did WHERE 1=0 and then were planning to do a

INSERT INTO MyNewTable
SELECT *
FROM MyOldTableIncludingIdentityColumn

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-27 : 09:58:52
quote:
Originally posted by Peso

And if you want to create an empty temp table, just add a nonsense WHERE to it.

select eno, ename into temptable from emp where 1 = 0


Peter Larsson
Helsingborg, Sweden


or
select Top 0 eno, ename into temptable from emp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-27 : 10:01:30
quote:
Originally posted by Peso

And if you want to create an empty temp table, just add a nonsense WHERE to it.

select eno, ename into temptable from emp where 1 = 0


Peter Larsson
Helsingborg, Sweden



Makes perfect sense to me




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -