Reputation: 183
i dynamicaly create Views which refering other Databases (mainly to import data from there)
use [RezepteDB]
in this DB i create a view like this
CREATE VIEW [dbo].bla as select * from ZutatenDB.dbo.Bla
Later i need the name of the Database, on which is the view based.
For this example 'ZutatenDB'.
How can i done this? a small function to pass the name of the view and return the name of the database.
Upvotes: 1
Views: 60
Reputation: 43636
One technique is to use sys.dm_sql_referenced_entities:
SELECT *
FROM sys.dm_sql_referenced_entities ('dbo.bla', 'OBJECT');
You can see the referenced server, database, schema and objects.
Upvotes: 1