如何在 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
How can I do the equivalent of "SHOW TABLES" in T-SQL?
提问by Andrew Crowe
I would like to do a lookup of tables in my SQL Server 2005 Express database based on table name. In MySQL
I would use SHOW TABLES LIKE "Datasheet%"
, but in T-SQL
this throws an error (it tries to look for a SHOW
stored procedure and fails).
我想根据表名在我的 SQL Server 2005 Express 数据库中查找表。在MySQL
我会使用SHOW TABLES LIKE "Datasheet%"
,但在T-SQL
这会引发错误(它尝试查找SHOW
存储过程并失败)。
Is this possible, and if so, how?
这是可能的,如果是,如何?
回答by JustinD
回答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_schema
views.
也寻找其他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
MS
is slowly phasing out methods other than information_schema
views. so for forward compatibility always use those.
MS
正在逐步淘汰information_schema
视图以外的方法。所以为了向前兼容,总是使用那些。