Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vidhya
Posting Yak Master
108 Posts |
Posted - 2008-05-06 : 03:42:09
|
| hi friends,I need query to insert all values from one table to another table. |
|
|
Anoop
Starting Member
6 Posts |
Posted - 2008-05-06 : 03:54:04
|
| Quite easy. See example.CREATE TABLE tbl1 (col1 int)INSERT INTO tbl1 VALUES (1)INSERT INTO tbl1 VALUES (2)INSERT INTO tbl1 VALUES (3)INSERT INTO tbl1 VALUES (4)INSERT INTO tbl1 VALUES (5)INSERT INTO tbl1 VALUES (6)CREATE TABLE tbl2 (col1 int)INSERT INTO tbl2 SELECT * FROM tbl1SELECT * FROM tbl2 |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2008-05-06 : 03:55:10
|
| Without seeing the table schemas, this is just a guess, but something like this should workInsert into table2select * from table1That will work if the columns in the two tables are the same. If not, you will need to specify the column in the insert and the select--Gail Shaw |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-06 : 04:13:32
|
| or are you trying create a new table with values from oldtable, then useSELECT * INTO NewTable FROM OldTable |
 |
|
|
srinivas_a9
Starting Member
1 Post |
Posted - 2008-05-06 : 04:16:24
|
| Hi Vidya,Suppose you have a table named emp with data. If you want to create a table with name employee with same structure as emp and you want to copy the emp data to employee table, then try the following single query to do this entire job:select * into employee from empRegards,Srinivas Asapu,Hyderabad, India.Mobile: +91 9849851752.E-Mails: a.srinivas9@gmail.com a_srinivas9@yahoo.co.in |
 |
|
|
|
|
|