Solved

Linking to tables in another database

Posted on 2011-09-30
3
220 Views
Last Modified: 2012-05-12
I have a copy of SQL Server 2008 R2 Management studio.

I am in one database and would like to know how to make a view of a table in another database.  

In the past I have had someone do this for me, so I already have a bunch of these views created to tables in this other db.

However, I need some additional ones made and need to know how to do this on my own,

Thanks.
0
Comment
Question by:snyperj
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36891653
select * from otherdatabase.dbo.othertable

hope this helps
0
 
LVL 2

Expert Comment

by:akku101
ID: 36892427
Try below code, change database,table and column names.
Create View [Vw_ViewName]
As

Select Top 10 
	Column1,
	Column2,
	Column3,
	Column4 
From 
	[Source_DateBaseName]..[TableName]

Open in new window

0
 
LVL 3

Accepted Solution

by:
pg_vinod earned 500 total points
ID: 36892633

Two ways...

1. You can "call" the view created on DB_a from DB_b
     use DB_b;
     go
     select * from DB_a..view_name;

2. you can create a view in you existing database(Db_b) referencing objects from other database (DB_a)
    use DB_b;
    go
    create view view_name
    AS
    begin
    select * or columns_name  
     from DB_a..table_name; .......
    end
   Go

  then call it
  select * from view_name  


HTH,
Vinod pottekkatt
 
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to union three related tables in one flat file? 8 48
backup and restore 21 30
SQL Query 2 34
Current Month Filter in Visual Studio 10 23
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

831 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