Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Getting all table names that match a WHERE mask

Author  Topic 

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-02 : 12:24:07
What query would return a list of table names that match a mask?

Example: Get all tables with OPT in the name.

SELECT
*
FROM
?
WHERE
NAME LIKE '%OPT%'

nr
SQLTeam MVY

12543 Posts

Posted - 2006-02-02 : 12:25:37
SELECT
*
FROM
sysobjects
WHERE
NAME LIKE '%OPT%'
and xtype = 'U'

also see information_schema.tables

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-02 : 13:50:12
Beautiful, Thanks!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-03 : 03:25:53
Also

Select table_name from Information_Schema.tables where table_name like '%OPT%'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-02-03 : 09:30:52
thanks madhivanan, two ways are better than one, and this one is slightly more efficient :)
Go to Top of Page
   

- Advertisement -