473,387 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Querying tables from different databases

Hello,

I am quite new to ms-sql and I have a problem : I want to create an SQL
request which would copy serveral records from a table in a given database
to another table (with exactly the same structure) in another database
(theses two tables and databases already exist).

Could you please tell me how to do this ? I dont know how to access two
different databases in a single SQL request.

Thank you for you help.

Jul 20 '05 #1
3 23163
You can use 3-part names to qualify the object references:

INSERT INTO MyDatabase1.dbo.MyTable1
SELECT *
FROM MyDatabase2.dbo.MyTable2

--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index....partmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

"Henri" <le******@nospam.inv> wrote in message
news:3f***********************@news.free.fr...
Hello,

I am quite new to ms-sql and I have a problem : I want to create an SQL request which would copy serveral records from a table in a given database to another table (with exactly the same structure) in another database
(theses two tables and databases already exist).

Could you please tell me how to do this ? I dont know how to access two different databases in a single SQL request.

Thank you for you help.

Jul 20 '05 #2
You can use 3-part naming like :

USE database1
GO
INSERT tbl(col1, col2, ...coln)
SELECT col1, col2, ..coln
FROM database2.dbo.tbl ;

--
--- Anith
Jul 20 '05 #3

"Henri" <le******@nospam.inv> wrote in message
news:3f***********************@news.free.fr...
Hello,

I am quite new to ms-sql and I have a problem : I want to create an SQL
request which would copy serveral records from a table in a given database
to another table (with exactly the same structure) in another database
(theses two tables and databases already exist).

Could you please tell me how to do this ? I dont know how to access two
different databases in a single SQL request.

use northwind
go
select * from pubs.dbo.authors
go
Basically you need to use the db name and the object owner.
Thank you for you help.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Peter Paskoff | last post by:
at first - canīt change the server version, so i have to live with the limitations of the version. since there is no ability to create queries between different databases in this version - how...
2
by: Kenneth Fosse | last post by:
Hi. I'm currently working on a project which involves the creation of a web page which reports selected data to customers from two back-end systems. I use ASP script language on IIS, the server...
3
by: Dov MORYUSEF | last post by:
Hi there, Is it possible to have a primary key - foreign key relationship between tables in different databases in DB2 ? (databases are installed in different physical servers) Thanks a lot...
10
by: Captain Nemo | last post by:
Hi I'm working on an ASP project where the clients want to be able to effectively perform SELECT queries joining tables from two different databases (located on the same SQL-Server). Does...
2
by: =?Utf-8?B?VGVycnk=?= | last post by:
Is it possible to join tables from different databases? If so, what is the format of the select statement? Both databases are on the same server. TIA, -- Terry
18
by: asi242 | last post by:
Hello, Good day to all... I just want to ask.. How would you connect two tables from 2 different databases using PHP scripts? Because, one database that contains customer table is dedicated to...
3
by: Aswanth | last post by:
Hi.., I'm having Two Stored Procedures in Two Different Databases.. Database1 - Employee Stored Procedure - Employee_Details Database2 - Company Stored Procedure - Company_Details
4
by: sganeshsvk | last post by:
sir, i want to store the same data values in two different databases at that same time in mysql using php programming. suppose any one databases data will lose then we use the other...
2
by: dandalero | last post by:
Hi, I'm joining tables from 2 different databases instance located on different SQL Server, I tried server.database.owner.table but I got the following error: "Could not find server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.