Showing posts with label alone. Show all posts
Showing posts with label alone. Show all posts

Sunday, February 19, 2012

Copy the table structure

Hi,
In SQL Server, Is there any DDL available to copy a table structure alone and not the data,
I believe 'SELECT * into new_table from table1' will copy both structure and data as well.
Please advice,
Thanks,
MiraJYou 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.

SELECT * INTO new_table FROM table1 WHERE 1 = 0|||Understand though that Indexes and constraints do not get copied over...

copy table structure

Hi,
In SQL Server, Is there any DDL available to copy a table structure alone and not the data,
I believe 'SELECT * into new_table from table1' will copy both structure and data as well.
Please advice,
Thanks,
SmithaYou can do:

select top 0 * into new_Table from table1;

--or
select top 0 * into new_Table from table1 where 1=0;

-- or in SQL Server 2005
select top(0) * into new_Table from table1;