StatCounter

View My Stats

Monday, February 4, 2008

To copy a Table Records

The query as Follows:

1. select * into NewTableName from OldTableName

It copies all records From old Table and create a new Table with all old table records


2. insert into to_TableName select column1,column2 from FromTableName


For Example Conside 2 Table
1.create table Employee(id1 int identity,name1 varchar(50),address varchar(100),city varchar(100))

2.create table NameCollextion(id1 int identity,name1 varchar(50))

For the above two table Employee,NameCollection ,If u want to copy all the Name Rows into NameCollection Table Follow the below query

insert into NameCollection(name1) select name1 from Employee

You can also use where condition for the above query
Example
Yo
insert into NameCollection(name1) select name1 from Employee where id1 between 1 and 50

No comments: