Solved

Linking to tables in another database

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

910 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

22 Experts available now in Live!

Get 1:1 Help Now