简体   繁体   English

如何从SQL Server CE数据库检索所有表名的列表?

[英]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]的表,例如INVclayINVcherriINVkelvinINVmorganINVgrandFunkINVgobbledygookINV2468WhoDoWeAppreciate等( 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: 要检查是否存在:

-- -

-- note that the sql compiler knows that it just needs to check for existence, so this is a case where "select *" is just fine -请注意,sql编译器知道它只需要检查是否存在,因此在这种情况下,“ select *”就可以了

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]中选择*,其中up​​per([name])如N'INV%')选择N'做适当的操作,因为存在基于此模式的表。

您可以尝试以下方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 SQL Server 中特定数据库的表中获取所有列名? - How can I get all column names from a table from a specific database in SQL Server? 如何从数据库中检索所有表名? - How to retrieve all table names from database? 如何在SQL Server 2012数据库中获取所有表名,行数和数据大小? - How can I get all table names, row counts and their data sizes in a SQL Server 2012 database? 如何从 SQL Server 中的表中获取列名? - How can I get column names from a table in SQL Server? 如何从临时表中检索字段名称(SQL Server 2008) - How to retrieve field names from temporary table (SQL Server 2008) 如何从SQL Server数据库中的“ SQL脚本”获取表名 - How to get the table names from “SQL script” in SQL Server database 如何从通用审核表中检索值,该审核表在SQL中重组为具有有意义列名的行集? - How can I retrieve the values from a generic audit table reconstituted as a rowset with meaningful column names in SQL? SQL Server CE我可以从与我的查询匹配的表中删除TOP或仅1条记录 - Sql Server CE can I delete TOP or only 1 record from table that matches my query 如何向以编程方式创建的SQL Server CE表添加索引? - How can I add an index to a SQL Server CE table created programmatically? 如何使用C#确定SQL Server CE表中是否存在列? - How can I determine whether a column exists in a SQL Server CE table with C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM