Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / SQL
Tip/Trick

Copy paste complete Table SQL Server

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
16 Dec 2011CPOL 16.5K   1   1
Using a very simple query we can make replica of existing table along with full data and datatypes
There is a pretty nice method available to transfer data from one table to another

Transfer data from existing table to new table:
SQL
select * into table2 from table1

Copy all data from table1 into table2 (it creates new table2 no need to write create statement)

It will create new table2 and transfer all data from table1 to table2

Transfer data from existing table1 to existing table2:

If you want to transfer data from one table to existing table2 then use
SQL
Insert into vt_FE_Role1
Select [Role] from vt_FE_Role

Do not include primary key column if it is set as identity. Otherwise you can use it.
You must take care of RDBMS if exists.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Pakistan Pakistan
This member doesn't quite have enough reputation to be able to display their biography and homepage.

Comments and Discussions

 
GeneralReason for my vote of 1 sql basics not tip Pin
Selvin17-Dec-11 4:23
Selvin17-Dec-11 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.