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.
For Example,
Can anyone help me to get it resolved.
Answers:
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.
Method 1
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0