Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I have two table Table1 ,Table2.From Table1 want to transfer data to Table2.Suppose :

Select * from Table1 where UserID between 5 and 10

Want to store above result to Table2.Both table Have same type of columns.How to transfer data from table to table? If have any query plz ask.Thanks in advanced.

share|improve this question

1 Answer

following INSERT INTO statement:

INSERT INTO TABLE2 SELECT * FROM TABLE1

Now suppose you do not want to copy all the rows, but only those rows that meet a specific criteria. Say you only want to copy those rows where COL1 is equal to "A." To do this you would just modify the above code to look like this:

INSERT INTO TABLE2 SELECT * FROM TABLE1 WHERE COL1 = 'A'

See how simple it is to copy data from one table to another using the INSERT INTO method? You can even copy a selected set of columns, if you desire, by identifying the specific columns you wish to copy and populate, like so:

INSERT INTO TABLE2 (COL1, COL2, COL3) 
SELECT COL1, COL4, COL7 FROM TABLE1

The above command copies only data from columns COL1, COL4, and COL7 in TABLE1 to COL1, COL2, and COL3 in TABLE2.

share|improve this answer
Additionnally if you want to avoid writing queries you can still use the export Wizard (right click on the db in SSMS then Taks menu). You will have to specify the table to which you want to transfer the data. – nopol Jan 30 '12 at 14:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.