Search code examples
sql-serversql-server-2014

Possible to choose table with a wildcard?


Using AdventureWorks2012, I want to select all tables of Production, can I do this using a wildcard like Prod%?

EDIT: Was trying to choose table with wildcard like this:

WHERE t.name in ('Sales%')  

In hope of getting all tables starting with "Sales.", but didn't work.

However using:

WHERE LIKE 'Sales%'

selects all tables that starts with Sales in the "second step", ie, Sales.SalesCustomer.

What I want to do:

select all "Sales.***"

Hope this makes more sense


Solution

  • Here you can find all table where table name start with temp hope it helps 
    
     select t.name,s.name as  schemaname from sys.tables t
       join sys.schemas s on s.schema_id = t.schema_id
       where 
      t.name like '%sales%'     and 
      s.name='sales'