Solved

SQL Server copy table

Posted on 2009-05-19
9
370 Views
Last Modified: 2012-05-07
How do i copy one table form one server to other in SQL Server 2005.

eg: from abc to xyz. and only thru querry. i know the way thru import.
0
Comment
Question by:aatishpatel
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 9

Expert Comment

by:ezraa
ID: 24423210
You can use this to create a new table and copy all items from the old table:

select *
into newtable
from oldtable
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24423215
if you already setuup a linked server, use

INSERT INTO TableName
SELECT [LinkedServerName].[DatabaseName].[shemaName].TableName
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24423232
i missed the something

INSERT INTO TableName
SELECT* from  [LinkedServerName].[DatabaseName].[shemaName].TableName


the above one will work when you are in the Destination db..

otherwise


INSERT INTO  [ServerName].[DatabaseName].[shemaName].TableName
SELECT* from  [LinkedServerName].[DatabaseName].[shemaName].TableName
0
 
LVL 2

Expert Comment

by:d1rtyw0rm
ID: 24423343
If the 2 database are not on the same server

You have to create a linked server to be able to access the databases on another server.  Here's a link that may be able to help you get started with linked servers:

http://www.databasejournal.com/features/mssql/article.php/3085211

Then you can use the following method as if the 2 database were on the same server

----------------------------------------------------------------------------------------------------------------------------

If the 2 database are on the same server

SELECT * INTO xyz.dbo.YourTableTemp FROM abc.dbo.YourTable

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).
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:aatishpatel
ID: 24423371
no that does not work
0
 
LVL 2

Expert Comment

by:d1rtyw0rm
ID: 24423469
yes it is
0
 

Author Comment

by:aatishpatel
ID: 24423511
i have SELECT *
INTO IHSMain.dbo.tblTest
FROM P001.dbo.preference_list

that does but does not import primary keys
0
 
LVL 2

Expert Comment

by:d1rtyw0rm
ID: 24423526
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).
0
 

Author Closing Comment

by:aatishpatel
ID: 31583057
thanx
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to pass 2 IN parameters to a stored procedure using SQL Server 2008? 6 30
Sql query 107 33
Error running stored procedure 11 19
SQL VIEW 7 25
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now