This is not something that has to be, and I don't know whether it's even possible, but just a thought I had.
I've got this simple query I put together for searching SQL databases for certain schemas, tables, and/or fields:
So far the code works very well. It gives me what I would actually be looking for practically all of the time, and a little bit of info that I wouldn't necessarily need, but might come in handy at times. That, and it fits totally on the screen, column-wise.
But what I'd like to do is set it up to where it pulls this from very database on any server I run it on. For instance, there are at least 5 or 6 MS SQL servers that I could currently need to query data from at work. If I could set this up to run on the server, regardless of database, and just pull everything, that'd be really helpful at times.
Thanks for any thoughts, references, or suggestions, even if the only answer is: "It's not possible."
I've got this simple query I put together for searching SQL databases for certain schemas, tables, and/or fields:
Code:
USE DatabaseName [GREEN]--change this line to match whatever database you need to search[/GREEN]
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SET NOCOUNT OFF
SELECT TABLE_CATALOG AS [Database]
,TABLE_SCHEMA AS [Schema]
,TABLE_NAME AS [TABLE]
,COLUMN_NAME AS [Column]
,ORDINAL_POSITION AS [OrdPos]
,COLUMN_DEFAULT AS [DefVal]
,IS_NULLABLE AS [Nullable]
,DATA_TYPE AS [Type]
,CHARACTER_MAXIMUM_LENGTH AS [Length]
,NUMERIC_PRECISION AS [Precision]
,NUMERIC_SCALE AS [Scale]
,'[' + TABLE_CATALOG + '].[' + TABLE_SCHEMA + '].[' + TABLE_NAME + ']' AS [CopyToSql]
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
[GREEN]--(TABLE_NAME LIKE '%TableName%') --Comment this line & line below if not specifying table name
-- AND --Comment this line & line above if not specifying table name
--(TABLE_SCHEMA LIKE '%SchemaName%') --Comment this line & line below if not specifying schema/user name
-- AND --Comment this line & line above if not specifying schema/user name[/GREEN]
(COLUMN_NAME LIKE '%Status%')[GREEN] --Comment this line if not specifying column name[/GREEN]
ORDER BY TABLE_CATALOG ,TABLE_SCHEMA ,TABLE_NAME ,COLUMN_NAME
So far the code works very well. It gives me what I would actually be looking for practically all of the time, and a little bit of info that I wouldn't necessarily need, but might come in handy at times. That, and it fits totally on the screen, column-wise.
But what I'd like to do is set it up to where it pulls this from very database on any server I run it on. For instance, there are at least 5 or 6 MS SQL servers that I could currently need to query data from at work. If I could set this up to run on the server, regardless of database, and just pull everything, that'd be really helpful at times.
Thanks for any thoughts, references, or suggestions, even if the only answer is: "It's not possible."