How do I get list of all tables in a database usin

2018-12-31 17:59发布

What is the best way to get the names of all of the tables in a specific database on SQL Server?

17条回答
深知你不懂我心
2楼-- · 2018-12-31 18:54
SELECT * FROM INFORMATION_SCHEMA.TABLES 

or

SELECT * FROM Sys.Tables
查看更多
忆尘夕之涩
3楼-- · 2018-12-31 18:55
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U' 
查看更多
唯独是你
4楼-- · 2018-12-31 18:55

you can simply select your database first

use database_name;

then just type

show tables;
查看更多
余生请多指教
5楼-- · 2018-12-31 18:57
--for oracle
select tablespace_name, table_name from all_tables;

This link can provide much more information on this topic

查看更多
人间绝色
6楼-- · 2018-12-31 19:00
exec sp_msforeachtable 'print ''?'''
查看更多
梦寄多情
7楼-- · 2018-12-31 19:01

Thanks to Ray Vega, whose response gives all user tables in a database...

exec sp_msforeachtable 'print ''?'''

sp_helptext shows the underlying query, which summarises to...

select * from dbo.sysobjects o 
join sys.all_objects syso on o.id =  syso.object_id  
where OBJECTPROPERTY(o.id, 'IsUserTable') = 1 
and o.category & 2 = 0 
查看更多
登录 后发表回答