Saturday, January 7, 2012

CREATE a table from another table in SQL Server

There may be a situation where you want to create a duplicate copy of an existing table .For this write a select statement with the fallowing syntax
select <column> into <newnametable> from <tablename>
Here i will show an example to creates a table with the name of customer from the table oldcustomers
select* into customer from oldcustomers
select*from customers

When you creates a new table from existing table then only columns and a data types will be copy but not the constrains and indexes

Insert Rows from One table to another:
To insert the rows from one table to another table and for this user can use insert statement with the fallowing statement
Insert into  select*from 
Insert into customers select cid,cname,cadd from oldcustomers

Create Temp table:
Select * into #orderstemp from orders
Post a Comment

Bel