How can I do the equivalent of “SHOW TABLES” in T-

2020-05-17 00:12发布

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).

Is this possible, and if so, how?

11条回答
放我归山
2楼-- · 2020-05-17 00:17

Try this:

USE your_database
go
Sp_tables
go
查看更多
唯我独甜
3楼-- · 2020-05-17 00:18

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

查看更多
【Aperson】
4楼-- · 2020-05-17 00:29

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

查看更多
做自己的国王
5楼-- · 2020-05-17 00:29

Try it :

SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE '%'
查看更多
叛逆
6楼-- · 2020-05-17 00:29

MS is slowly phasing out methods other than information_schema views. so for forward compatibility always use those.

查看更多
劳资没心,怎么记你
7楼-- · 2020-05-17 00:30

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

sp_tables 'Database_Name'
查看更多
登录 后发表回答