Solved

Linking to tables in another database

Posted on 2011-09-30
3
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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

696 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