Thursday, November 20, 2008

Can we clone a table structure to temp table in SQL server? (Statement, create, insert )

Can we clone a table structure to temp table in SQL server? (Statement, create, insert )

- If you only want the structure:
way 1: use SQL manager > select database > select the tables > right click > copy > Use SQL Query Analyzer > select to correct database > Run the script!
way 2: Select Top 0 * into new_table_name from old_table_name
way 3: select * into new_table_name from old_table_name where 1=2

- This will include the data as well:
select * into new_table_name from old_table_name

No comments: