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 2005 Forums
 Transact-SQL (2005)
 Replicate only Table column names

Author  Topic 

ranalk
Starting Member

49 Posts

Posted - 2012-08-02 : 10:13:06
Hi,

Lets say I have a table with 50 columns and I would like to create an empty temp table with the same column names without typing each column name manually.
How can I do it ?

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-02 : 10:17:58
[code]
SELECT TOP 0 * INTO #NewTable FROM YourCurrentTable
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ranalk
Starting Member

49 Posts

Posted - 2012-08-02 : 10:31:59
Is there a possibility to use it with the following command?
Declare @Totals TABLE (***all column names***)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-02 : 10:34:34
nope...you've to manually copy it in that case after running a query on information_schema.columns catalog view

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-02 : 10:35:32
Also please keep in mind that @ tables are table variables and not temp tables

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ranalk
Starting Member

49 Posts

Posted - 2012-08-02 : 10:58:47
Thanks
Go to Top of Page
   

- Advertisement -