Solved

SQL Server copy table

Posted on 2009-05-19
9
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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
 

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

738 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