Friday, August 22, 2008

Ms Sql Server Create Table From Another Table

For the purpose we will use the method SELECT INTO :

This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.



---- Create new table and insert into table using SELECT INSERT

SELECT Column1, Column2 INTO NewTable FROM oldTable WHERE 1 = 2


Th sql above will copy the structure only

To copy selected data too we need to do the same as :


---- Create new table and insert into table using SELECT INSERT

SELECT Column1, Column2 INTO NewTable FROM oldTable WHERE