In SQL Server 2016 Management Studio, I have multiple databases.
I would like to find out which tables in which databases have a column whose name contains a string. How can i do that?
Is it possible to search within the Object Explorer window?
In SQL Server 2016 Management Studio, I have multiple databases.
I would like to find out which tables in which databases have a column whose name contains a string. How can i do that?
Is it possible to search within the Object Explorer window?
4条答案
按热度按时间eivgtgni1#
You can use
sp_MSForeeachdb
This approach will gather INFORMATION_SCHEMA.COLUMNS for each database on your server
EDIT - Requested Commentary
The First query creates an EMPTY Structure to hold the Information_Schema
Then we DECLARE @SQL which contains the SQL we want to execute for each database. Notice the ;Use [?];
Then we simply select the #Temp table for the desired results
t0ybt7op2#
You would need to iterate the databases on the server,
performing the following command for each one, using
Doing it with a cursor
7gyucuyw3#
run the following on each database, or using
cursor
anddynamic sql
for iterating each databaseupdate: for fuzzy lookup, use
B.name like '%serarch_pttern%
,%
means any leading or trailing charactersioekq8ef4#
@Tim I agree with John. Here is an example of the code I used yesterday to find out somewhat similar to what your requirement is. This chunk of code will produce a list of tables and columns with that specific string within the data base you choose to run this query on.