Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server copy table

Posted on 2009-05-19
9
Medium Priority
?
389 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 2000 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

705 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