Tuesday, June 30, 2015

Query to get the names of all tables in SQL

SQL Server 
USE your_database SELECT name FROM sys.tables


SQL Server - get the fields info
SELECT TABLE_SCHEMA, TABLE_NAME, 
       COLUMN_NAME, substring(DATA_TYPE, 1,1) AS DATA_TYPE
FROM information_schema.COLUMNS  

ORDER BY TABLE_SCHEMA, TABLE_NAME, ORDINAL_POSITION


MySQL
select TABLE_NAME from INFORMATION_SCHEMA.TABLES
where TABLE_TYPE = 'BASE TABLE'