Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come ottengo l'elenco di tutte le tabelle in un database usando TSQL?

SQL Server 2000, 2005, 2008, 2012, 2014, 2016, 2017 o 2019:

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'

Per mostrare solo le tabelle di un particolare database

SELECT TABLE_NAME 
FROM [<DATABASE_NAME>].INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE'

Oppure,

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE' 
    AND TABLE_CATALOG='dbName' --(for MySql, use: TABLE_SCHEMA='dbName' )

PS:per SQL Server 2000:

SELECT * FROM sysobjects WHERE xtype='U'