Reputation: 769
In order to minimize the effort to write a particular query again and again. How can we dynamically pass a particular keyword that can be searched throughout the database that is matched or not?
Upvotes: 0
Views: 263
Reputation: 769
Below is the AutohotKey Script:
Compile below script and run it. Usage: In ms-sql window, type qc# and it will ask you for the keyword to search throught the database. Once you type the keyword and enter it. It will type the whole script. Execute it and see the magic.
Here is the Script:
:?*:qc#::
varQ =
(
SELECT
'select * from [' {+} s.name {+} '].' {+} t.name AS Table_Name,
c.name AS Column_Name
FROM
sys.columns c,
sys.tables t,
sys.schemas s
WHERE
s.name NOT in ('logs','legacy','cdc')
and t.name NOT LIKE '`%[0-9]`%'
and c.object_id = t.object_id
AND t.schema_id = s.schema_id
AND c.name LIKE 'xxx'
order by 1
)
Input, thename, v,{Enter}{Space}
StringLen, MyLen, thename
MyLen++
thename = `%%thename%`%
StringReplace, varQ, varQ, xxx, %thename%, All
SendInput {BackSpace %MyLen%}+%varQ%
Return
Upvotes: 1