This is a discussion on Querying tables from different databases within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello, I am quite new to ms-sql and I have a problem : I want to create an SQL ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| |||
| 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" <lemartin@nospam.inv> wrote in message news:3f8065cb$0$27019$626a54ce@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. > > > |
| ||||
| "Henri" <lemartin@nospam.inv> wrote in message news:3f8065cb$0$27019$626a54ce@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. > > > |