I am working on a project that has multiple contexts because data are being pulled form different databases.
We have around hundreds of databases, 1 database have hundreds of tables too, so going through a lot of databases are there to find a table is painstaking.
I only have code in finding a table name from a specific database through column name like this:
SELECT c.name AS 'ColumnName'
,t.name AS 'TableName'
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE '%mycolumn%'
ORDER BY TableName
,ColumnName;
But sometimes I already know the table name but don't know which database it belongs to. Can anyone point me to the right code?
UPDATE:
I meant to say database. for a clearer explanation, here is our connectionstring, as you can see I just added few databases.
But, it can grow based on what data we need in our codes. I need the database name that will serve as my context (I'm using dbscopecontext) as well as be able to query like this
select * from [MyDatabase].[dbo].[MyTable]
Because just selecting from the query pad like below gives an error.
select * from [dbo].[MyTable]
<add name="EContext" connectionString="server; Database=E; providerName="System.Data.SqlClient" />
<add name="MContext" connectionString="server; Database=M; providerName="System.Data.SqlClient" />
<add name="AContext" connectionString="server; Database=A; providerName="System.Data.SqlClient" />
<add name="BaContext" connectionString="server; Database=B; providerName="System.Data.SqlClient" />
<add name="WConntextntext" connectionString="server; Database=W; providerName="System.Data.SqlClient" />
<add name="WpContext" connectionString="server; Database=Wp; providerName="System.Data.SqlClient" />
<add name="Maontext" connectionString="server; Database=MA; providerName="System.Data.SqlClient" />
<add name="BlsContext" connectionString="server; Database=Bls; providerName="System.Data.SqlClient" />
<add name="BiContext" connectionString="server; Database=Bi; providerName="System.Data.SqlClient" />
</connectionStrings>
Thanks in advance