如何在 T-SQL 中执行等效于“SHOW TABLES”的操作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/124205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 23:34:51  来源:igfitidea点击:

How can I do the equivalent of "SHOW TABLES" in T-SQL?

sqltsqlsql-server-2005

提问by Andrew Crowe

I would like to do a lookup of tables in my SQL Server 2005 Express database based on table name. In MySQLI would use SHOW TABLES LIKE "Datasheet%", but in T-SQLthis throws an error (it tries to look for a SHOWstored procedure and fails).

我想根据表名在我的 SQL Server 2005 Express 数据库中查找表。在MySQL我会使用SHOW TABLES LIKE "Datasheet%",但在T-SQL这会引发错误(它尝试查找SHOW存储过程并失败)。

Is this possible, and if so, how?

这是可能的,如果是,如何?

回答by JustinD

I know you've already accepted an answer, but why not just use the much simpler sp_tables?

我知道您已经接受了答案,但为什么不使用更简单的sp_tables呢?

sp_tables 'Database_Name'

回答by Hector Sosa Jr

This will give you a list of the tables in the current database:

这将为您提供当前数据库中的表列表:

Select Table_name as "Table name"
From Information_schema.Tables
Where Table_type = 'BASE TABLE' and Objectproperty 
(Object_id(Table_name), 'IsMsShipped') = 0

Some other useful T-SQL bits can be found here: http://www.devx.com/tips/Tip/28529

其他一些有用的 T-SQL 位可以在这里找到:http: //www.devx.com/tips/Tip/28529

回答by ducnguyen.lotus

Try this:

尝试这个:

USE your_database
go
Sp_tables
go

回答by PJB

Try this

尝试这个

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'Datasheet%'

回答by Mladen

Try this :

尝试这个 :

select * from information_schema.columns
where table_name = 'yourTableName'

also look for other information_schemaviews.

也寻找其他information_schema观点。

回答by Mark Brackett

And, since INFORMATION_SCHEMA is part of the SQL-92 standard, a good many databases support it - including MySQL.

而且,由于INFORMATION_SCHEMA 是 SQL-92 标准的一部分,很多数据库都支持它——包括MySQL

回答by Mark Brackett

Try it :

尝试一下 :

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%'

回答by Tom

Try following

尝试以下

SELECT table_name
FROM information_schema.tables
WHERE
table_name LIKE 'Datasheet%'

回答by Ramshad Abdulraheem

One who doesn't know the TABLE NAME will not able to get the result as per the above answers.

不知道 TABLE NAME 的人将无法根据上述答案获得结果。

TRY THIS

尝试这个

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='dbo'; 

回答by Mladen

MSis slowly phasing out methods other than information_schemaviews. so for forward compatibility always use those.

MS正在逐步淘汰information_schema视图以外的方法。所以为了向前兼容,总是使用那些。