Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Create view from another database?

Author  Topic 

JLW
Starting Member

1 Post

Posted - 2004-10-08 : 00:48:28
Hi all,

I would like to pull data from, say database1, into a view on database2 combined with data from database2. They are both running on the same SQL Server. Is this possible and how would I go about doing this?

Thanks!

hgorijal
Constraint Violating Yak Guru

277 Posts

Posted - 2004-10-08 : 00:52:42
use database2
go
create view my_view as select * from database1.dbo.my_db1_table

Hemanth Gorijala
BI Architect / DBA...
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-10-08 : 00:54:30
You can select from another database using a 3 part syntax : database.owner.object. For example : Select * from Northwind.dbo.Products.

So your view could be :

Create View vwTest

AS

Select col1, col2 FROM db1.dbo.customers
UNION ALL
Select col1, col2 FROM db2.dbo.customers

GO

Hope that helps


Damian
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-10-08 : 00:55:06
Damn, he beat me to it



Damian
Go to Top of Page
   

- Advertisement -