?
Solved

Linking to tables in another database

Posted on 2011-09-30
3
Medium Priority
?
236 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 2000 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 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

762 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