[英]How can I Retrieve a List of All Table Names from a SQL Server CE database?
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? 是否有一些SQL将返回表名列表或(切入正题)将返回关于是否存在具有特定模式的表名的布尔值?
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). 具体来说,我需要知道数据库中是否存在名为
INV[Bla]
的表,例如INVclay
, INVcherri
, INVkelvin
, INVmorgan
, INVgrandFunk
, INVgobbledygook
, INV2468WhoDoWeAppreciate
等( INV
部分是我正在寻找的;表名的其余部分几乎可以是任何内容)。
IOW, can "wildcards" be used in a SQL statement, such as: IOW,可以在SQL语句中使用“通配符”,例如:
SELECT * tables
FROM database
WHERE tableName = 'INV*'
or how would this be accomplished? 或将如何实现?
This should get you there: 这应该使您到达那里:
SELECT *
FROM INFORMATION_SCHEMA.TABLES
where table_name LIKE '%INV%'
EDIT: fixed table_name
编辑:固定的
table_name
To check for exists: 要检查是否存在:
-- -
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'; 如果存在(从[sys]。[tables]中选择*,其中upper([name])如N'INV%')选择N'做适当的操作,因为存在基于此模式的表。
您可以尝试以下方法:
SELECT name FROM sys.tables where name LIKE 'INV%';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.