Skip to content
Advertisement

SQL query on certain database names

I currently have many databases on a server. I want to run a query on only databases that end in “AccountsLive”.

Not all of them end with this, so I kind of want to do a wildcard %AccountsLive query and not using a WHERE NOT name IN('master', 'tempdb', 'model', 'msdb')

Is this possible?

Below is the code I currently have:

Advertisement

Answer

You can put list of table names in a table variable and query them accordingly. I have also added schema as dbo, to make the name as three part name, assuming the table in the dbo schema.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement