If you have a table in a database and you would like to copy the table to another database, use this query:
SELECT * INTO AdventureWorks.dbo.CustomersTemp FROM Northwind.dbo.Customers
Just remember that using this query will only transfer the schema and data. It does not transfer the indexes, foreign keys, statistics etc.
If you want to transfer all the objects from one database to another, open Sql Server Management Studio > Right click on your database > All Tasks > Generate SQL Scripts. Then run these scripts against the new database.
Transfer both schema and data
To copy both data and schema, use the Microsoft SQL Server Database Publishing Wizard 1.1. This tool works for both SQL 2000 and SQL 2005 and generates a single SQL script file which can be used to recreate a database (both schema and data).
Thank you! I was searching the net to copy a table and found ur blog.
ReplyDeleteI am still looking for pure copy table without using SQL Statement (SQLServer SMO is prefered) but I think I am going to use your tips if none I can find...
ReplyDeleteNice blog :)
___________
Daniel - averagecoder.net
averagecoder: The solution you choose also depends on the size of your table. Using the scripts 'may' not feasible if your table contains a million rows.
ReplyDeletethanks for the help :-)
ReplyDeleteThanks a lot! Nice blog!
ReplyDeleteyou're a star!
ReplyDeleteyour a retard lmao
ReplyDeleteThanks for this. But does this work with large tables?
ReplyDeleteAveragecoder - have you tried Import/Export as a solution to copying tables? Unfortunately, this does not work with tables with 1000s of rows.
Thanks for the Help!
ReplyDeleteThanx it really saved my time and effort
ReplyDeleteit creates a new table. i want to copy just data from one table to another
ReplyDeleteThanks for the post.
ReplyDeletethank u
ReplyDeletethanks buddy
ReplyDeleteThankyou so much buddy, I tried in many ways to get this done, but finally your solution helped me.
ReplyDeleteNice blog.
Thank you for sharing knowledge and helping others with it.
ReplyDeleteAmir
From db2, type this in your query analyzer:
ReplyDeleteINSERT INTO copytable SELECT * FROM db1.dbo.origtable
...........................Thankyou
Thanks, it works!
ReplyDeleteThank you!
ReplyDelete- venky
Thanks ! ! ! ! !
ReplyDeleteThank you! Perfect
ReplyDeleteThanks, dude. Still helpful.
ReplyDeleteinsert into Suprotim_Agarwal_comments values('Thanks a lot bro');
ReplyDeleteHi,
ReplyDeletehttp://hightechpost.blogspot.com/2011/10/copying-table-in-sql-server-2005.html
check it in simple way for:
1)Copy table from same Database:
2)Copy table from another Database:
3)Copy few columns into the destination table:
regards
hightechpost
thanks alot dear......
ReplyDeletethanks but my databases are present on different machine (server) then what should i do?
ReplyDeletethanks but my databases are present on different machine (server) then what should i do?
ReplyDeletemy email ID is : aju184@gmail.com