How can I Retrieve a List of All Table Names from a SQL Server CE database?

霸气de小男生 提交于 2019-12-13 21:07:00

问题


Is there some SQL that will either return a list of table names or (to cut to the chase) that would return a boolean as to whether a tablename with a certain pattern exists?

Specifically, I need to know if there is a table in the database named INV[Bla] such as INVclay, INVcherri, INVkelvin, INVmorgan, INVgrandFunk, INVgobbledygook, INV2468WhoDoWeAppreciate, etc. (the INV part is what I'm looking for; the remainder of the table name could be almost anything).

IOW, can "wildcards" be used in a SQL statement, such as:

SELECT * tables 
FROM database 
WHERE tableName = 'INV*'

or how would this be accomplished?


回答1:


This should get you there:

SELECT * 
FROM INFORMATION_SCHEMA.TABLES
 where table_name LIKE '%INV%'

EDIT: fixed table_name




回答2:


To check for exists:

--

-- note that the sql compiler knows that it just needs to check for existence, so this is a case where "select *" is just fine

if exists (select * from [sys].[tables] where upper([name]) like N'INV%') select N'do something appropriate because there is a table based on this pattern';




回答3:


You can try the following:

SELECT name FROM sys.tables where name LIKE 'INV%';


来源:https://stackoverflow.com/questions/25391415/how-can-i-retrieve-a-list-of-all-table-names-from-a-sql-server-ce-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!