Solved

Linking to tables in another database

Posted on 2011-09-30
3
192 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 142

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

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…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now