I want to write a query to display the list of tables in a specific database along with its table type and number of attributes for that table.
Can anyone help me to get it resolved.
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Sure, you can query systems tables like that :
SELECT TABLE_NAME,TABLE_ROWS,TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DATABASENAME'
Change DATABASENAME for your db name. There is many others options you can display, check :
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DATABASENAME'
EDIT : Version with JOIN so we can count columns
SELECT C.TABLE_NAME,T.TABLE_ROWS,T.TABLE_TYPE, count(C.table_name) AS COLUMNS_NUMBER FROM INFORMATION_SCHEMA.TABLES AS T INNER JOIN INFORMATION_SCHEMA.COLUMNS AS C ON C.TABLE_SCHEMA = T.TABLE_SCHEMA AND T.TABLE_NAME = C.TABLE_NAME WHERE T.TABLE_SCHEMA='DATABASENAME' GROUP BY C.TABLE_NAME, T.TABLE_SCHEMA,T.TABLE_ROWS,T.TABLE_TYPE