Sunday, February 19, 2012

Can I setup a Global Public View in SQL Server ?

I need a master view that gets data from different DBs located on the same SQL Server (similar with Oracle feature that allows to get data from different schemas).

Is it possible to create such a view ?

Thanks

Yes you can do it:

Create view my_view
as
select *
from
database1.schema3.table3
join database2.schema5.table6 on ....
union database3.schema5.table8


Keep in mind that if you are going to grant select privileges on this view to a specific user/role, you must grant same privileges on all underlyeing tables.

To make things simpler you can also create synonyms to that tables, like in Oracle, but you have to qualify whem with database names.

|||Thanks !

And this view can reside in any of the DBs, isn't it ?|||Yes, it can reside on any USER db, don't place it in master, tempdb, etc.

No comments:

Post a Comment