The database is on a remote Linux server, I am using Windows.
I want to retrieve the table with the most rows in MySQL, but I am on a Windows client.
I have about 200 tables. I have to click their table name one by one to figure out the row count.
The databases has many tables, I can get their rows by executing
select count(*) from table
This will retrieve the rowcount one by one.
My Question
Is there a quick method to get the table with the most rows in MySQL workbench on Windows?
how about:
SELECT TABLE_NAME
,TABLE_ROWS
FROM INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_ROWS DESC
SELECT MAX(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'db_name'
=> This will return the maximum number of rows a table have.
SELECT table_name, MAX(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'db_name'
=> This will return the maximum number of rows a table have with the table name
Quick Links
The INFORMATION_SCHEMA TABLES Table
Get record counts for all tables in MySQL database
SELECT TABLE_ROWS, TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '{{schema_name}}'
ORDER BY TABLE_ROWS DESC
LIMIT 1;
This will tell you the table name with most number of rows. Replace schema_name with your database before executing query.
Related
I have multiple tables in my multiple databases.
On different servers, i use MySQL / PostgreSQL / MS SQL.
I keep short table namesbut the comments given to the tables are with full explanation.
I want query that will show me tables ending with "com" and also the comment given to each table (table's comment).
In MySQL, I know:
SELECT table_name FROM information_schema.tables where table_name like "%com"
But this shows all tables from all databases.
For MySQL, check out following:
SELECT table_name FROM information_schema.tables;
will show all table names in all databases;
SELECT table_name,table_comment FROM information_schema.tables
will show all table names + comment in all databases;
interesting thing, you can fire
SELECT * FROM information_schema.tables;
to know what all info you can get of a table.
SELECT table_name,table_comment FROM information_schema.tables
where
table_schema = 'sifr_b';
will show all table names + comment in "sifr_b" database;
SELECT table_name,table_comment FROM information_schema.tables
where
table_schema = 'sifr_b' and
table_name like "%com";
will show those table names + comment in "sifr_b" database, that have table name ending with "com";
Could not validate table exists in MySQL.
Tried below query but no output.
if !(select * from information_schema.tables where table_name='sy_code')
To see the schema of a table, use query
DESCRIBE table_name;
To see all the existing table in our database, use query
SELECT table_name FROM information_schema.tables WHERE table_schema = 'your_db'
I would ask how to get the last modified date of an mysql table? For the last modified date of an mysql table, I mean the last time that the table is changed,for example,due to table insert, delete,update,truncate, etc.
As you can read in mysql documentation for The INFORMATION_SCHEMA TABLES Table,
you can get the update_time (and other information) with a simple query:
SELECT update_time
FROM information_schema.tables
WHERE table_name = 'table_name';
It gives you the last modified one.
SELECT UPDATE_TIME
FROM information_schema.tables WHERE
TABLE_SCHEMA = 'your_dbname' AND TABLE_NAME = 'your_tablename'
I know how to use queries but I've never had to use one for this particular tasks .. I know about the SHOW TABLES; command .. How can I write a query to check if a particular table exists in a MYSQL database .. For example , a query that checks if table MEMBERS exists in database called USERS ??
You can use INFORMATION_SCHEMA.TABLES
USE USERS;
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'MEMBERS'
Searching Table:
select * from
information_schema.tables
where table_name like '%MEMBERS%'
Searching Column:
select * from
information_schema.columns
where table_name like '%COLUMN%'
How are the tables ordered returned by "SHOW TABLES"?
For example the output for the information_schema database looks like this:
CHARACTER_SETS
COLLATIONS
COLLATION_CHARACTER_SET_APPLICABILITY
COLUMNS
COLUMN_PRIVILEGES
ENGINES
EVENTS
FILES
GLOBAL_STATUS
GLOBAL_VARIABLES
KEY_COLUMN_USAGE
PARAMETERS
PARTITIONS
PLUGINS
PROCESSLIST
PROFILING
REFERENTIAL_CONSTRAINTS
ROUTINES
SCHEMATA
SCHEMA_PRIVILEGES
SESSION_STATUS
SESSION_VARIABLES
STATISTICS
TABLES
TABLESPACES
TABLE_CONSTRAINTS
TABLE_PRIVILEGES
TRIGGERS
USER_PRIVILEGES
VIEWS
INNODB_CMP_RESET
INNODB_TRX
INNODB_CMPMEM_RESET
INNODB_LOCK_WAITS
INNODB_CMPMEM
INNODB_CMP
INNODB_LOCKS
See Sergei Golubchik's answer from SHOW DATABASES does not order infomation_schema correct: "no SHOW command sorts the result".
If you need the tables names sorted you can query information_schema.tables, something like:
select table_name from information_schema.tables
where table_schema = 'your_db_name' order by table_name;
Try this:
SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'information_schema' ORDER BY TABLE_NAME
The below code works pretty well for me to list specific tables on any of my database and sort them by their name as asked.
SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'your_database_here' AND TABLE_NAME LIKE '%letters_from_your_table_here%' ORDER BY TABLE_NAME DESC