Question

In Management Studio, you can right click on the tables group to create a filter for the table list. Has anyone figured out a way to include multiple tables in the filter? For example, I'd like all tables with "br_*" and "tbl_*" to show up.

Anyone know how to do this?

Was it helpful?

Solution

You might be able to roll your own addon to SMSS that would allow you to do what you are looking for:

The Black Art of Writing a SQL Server Management Studio 2005 Add-In

Extend Functionality in SQL Server 2005 Management Studio with Add-ins

The first one is specifically for searching and displaying all schema objects with a given name so you might be able to expand upon that for what you are looking for.

OTHER TIPS

No, you can't do this. When we first got Management Studio I've tried every possible combination of everything you could think of: _, %, *, ", ', &&, &, and, or, |, ||, etc...

I've used Toad for SQL Server (freeware version) which has very nice filtering options.

I'm using SQL Server Management Studio v17.1 and it has a SQL injection bug in it's filter construction, so you can actually escape default

tbl.name like '%xxx%' 

and write your own query (with some limitations). For example to filter tables that are ending with "_arch", "_hist", "_purge" I used following filter value

_arch') and RIGHT(tbl.name, 5) != N'purge' and RIGHT(tbl.name, 4) != N'hist' and not(tbl.name like N'bbb

You can use SQL Server Profiler to see the constructed query and adjust it as needed.

Not sure if this same bug is available in previous SQL Management Studio versions or when it will be fixed, but for now I'm happy with the result.

At first it looks like it could use a CONTAINS query (e.g. "br_*" OR "tbl_*"), but it doesn't seem to. It seems to only support a value that is then passed into a LIKE clause (e.g. 'app' becomes '%app%').

As others have said, you cannot do this in SQL Server Management Studio (up and including 2014).

The following query will give you a filtered list of tables, if this is all you need:

SELECT
    CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) AS TABLE_SCHEMA_AND_NAME,
    TABLE_SCHEMA,
    TABLE_NAME
FROM
    INFORMATION_SCHEMA.TABLES
WHERE
    TABLE_SCHEMA IN ('X', 'Y', 'Z') -- schemas go here
ORDER BY
    TABLE_SCHEMA,
    TABLE_NAME;

The SQL injection method still works (somewhat) as of SSMS 2017 v17.8.1, although it puts brackets around the % symbol, so it will interpret those literally.

If you're using the Name->Contains filter, Profiler shows: ... AND dtb.name LIKE N'%MyDatabase1%')

So, in the Name->Contains field: MyDatabase1') OR (dtb.name LIKE 'MyDatabase2 should do it for simple cases.

Your in luck, I just conquered that feat, although my success is small because you can filter by schema which would allow you see more than 1 table but you have to type the filter text in each time you want to change it.

This is old I know, but it's good to know that it can works if you input just entering the "filter" text. Skip * or % or any other standard search characters, just enter br_ or tbl_ or whatever you want to filter on.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top