SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Replicate only Table column names
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ranalk
Starting Member

48 Posts

Posted - 08/02/2012 :  10:13:06  Show Profile  Reply with Quote
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

India
47099 Posts

Posted - 08/02/2012 :  10:17:58  Show Profile  Reply with Quote

SELECT TOP 0 * INTO #NewTable FROM YourCurrentTable


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

Go to Top of Page

ranalk
Starting Member

48 Posts

Posted - 08/02/2012 :  10:31:59  Show Profile  Reply with Quote
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

India
47099 Posts

Posted - 08/02/2012 :  10:34:34  Show Profile  Reply with Quote
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

India
47099 Posts

Posted - 08/02/2012 :  10:35:32  Show Profile  Reply with Quote
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

48 Posts

Posted - 08/02/2012 :  10:58:47  Show Profile  Reply with Quote
Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000