this seems stupid, but I really don't know this thing.
Today, I am in need to get number of properties in a mysql table (in phpmyadmin).
Can I get the count of the column names in phpmyadmin (mysql)?
For that You can write sql query in phpmyadmin.
SELECT count(*)
FROM information_schema.columns
WHERE table_name = '<table_name>'
Related
I am sometimes curious just to do a quick command line query to count the number of tables in my database. Is that possible in MySQL? If so, what is the query?
You can try this SQL query:
USE <database_name>;
SELECT COUNT(*) FROM sys.tables;
In the command above, replace the placeholder with the actual database name.
Is there any way to know the time when last select statement has been performed on a table? I am using the InnoDB storage engine.
I have tried with the following query:
select update_time,table_name from information_schema.tables where table_schema='databasename';
..but I'm receiving NULL in the update_time column.
Unless you manually update a last_accessed-field on the table, my best bet would be to add query logging and parse the log-files.
I googled and found these relates questions:
When was the last time a mysql table was accessed?
How do you get the last access (and/or write) time of a MySQL database?
SELECT UPDATE_TIME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbname'
AND TABLE_NAME = 'tabname'`
When writing a query, can I reference the current database's name, sort of like with the this keyword in Java? I am writing a script that I will run against several similar databases, and I need to query the information_schema.KEY_COLUMN_USAGE table with the CONSTRAINT_SCHEMA column in my WHERE clause.
SELECT DATABASE() gives you the selected database
http://dev.mysql.com/doc/refman/5.0/en/creating-database.html
I am trying to get a list of tables and their number of rows. I have been using this query:
SELECT TABLE_NAME, TABLE_ROWS
FROM INFORMATION_SCHEMA WHERE TABLE_SCHEMA = 'myDatabase'
I am finding this sometimes returns null. What I would like to do is catch this probably doing something similar to
IFNULL ( TABLE_ROWS, SELECT COUNT(*) FROM ????)
Only I'm not sure what I should enter for ????
how to make it dynamic based on the TABLE_NAME column?.
Edit: Additional information: I found that the 'tables' not displaying are actually views.
Might as well do
SHOW TABLE STATUS FROM YOUR_DATABASE;
It always return a column named as Rows which is number of rows in that table.
From the documentation:
The TABLE_ROWS column is NULL if the table is in the INFORMATION_SCHEMA database.
So, you will propably not need it.
I would like to know how many rows are in each table in my database. I've come so far as to having
select count(*) _tablename_;
However i would need to do that on each and every table - and there are a lot. What would me the best way to get a print-out with the table name and it's row count?
SELECT table_name, table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<your db>';
I also hope you realise there's an error in your query: it's missing a FROM.
This following query will return number of rows in each table but it doesn't seem to return exact value all the time
SELECT table_name, table_rows
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<your db>';
TABLE_ROWS: The number of table rows in the partition. For partitioned InnoDB tables, the row count given in the TABLE_ROWS column is only an estimated value used in SQL optimization, and may not always be exact...
for more https://dev.mysql.com/doc/mysql-infoschema-excerpt/5.5/en/partitions-table.html
In addition to SQL queries by others, one can also use Workbench GUI to get the row-counts of each table. To do this, Launch Workbench -> Connect to Db -> right click Db and select "Schema Inspector" (as in Screenshot below - I have highlighted the "Rows" column):
HTH.