Selecting data from different databases

By Bill Graziano on 7 September 2000 | Tags: SELECT


GianMarco writes "I need to make a view that includes external data in different DB (still sql, on the same server). How can I do it? In acces I can link external table and then create my query but in Sql?"

You can type something like this from any database:

SELECT *
FROM pubs.dbo.authors


Table names (and all database objects) can be qualified with the database name and owner name of the object with the syntax:

. . . FROM DatabaseName.OwnerName.ObjectName . . .

You could also use something like this:

SELECT *
FROM pubs..authors


This comes in handy when your ISP defaults to having you create objects rather than being aliased to the DBO.


Related Articles

Joining to the Next Sequential Row (2 April 2008)

Writing Outer Joins in T-SQL (11 February 2008)

How to Use GROUP BY with Distinct Aggregates and Derived tables (31 July 2007)

How to Use GROUP BY in SQL Server (30 July 2007)

SQL Server 2005: Using OVER() with Aggregate Functions (21 May 2007)

Server Side Paging using SQL Server 2005 (4 January 2007)

Using XQuery, New Large DataTypes, and More (9 May 2006)

Counting Parents and Children with Count Distinct (10 January 2006)

Other Recent Forum Posts

Why am I receiving an error about a column in the select list not being in an aggregate function or in the GROUP BY? (6h)

How to I insert records based on one to many relationship? (1d)

Transfer to new windows 11 computer (9d)

Pivot data but keep equal number per metric (12d)

Change Font Size In T-SQL Message Window? (13d)

Who has joined and who has left (15d)

Linked Server Selection Query Fails with "MS DTC has stopped this transaction" (19d)

Query almost perfect but brings wrong record (20d)

- Advertisement -