Saturday, April 3, 2010

How to create a new table schema from the existing table schema in SQL Server?

Some time we need to replicate existing schema of a table, to test something or whilst doing any demo.. Following method could be used:
Method 1: This is really easy and simple.
Select * into NewTable From ExistingTable Where 1>2
1>2 condition will never be true so no data will be transferred. If you want to replicate table with data as well, don't provide any condition.
You can also select some columns from the existing table and create a new table based on it. E.g.
Select Column1, Column2 into NewTable From ExistingTable Where 1>2, however, it's quiet obvious that these columns should be present in the existing table.

1 comment: