Is there a query that will show the last created table in a database?
+6
A:
Across all databases within your MySQL instance:
SELECT *
FROM information_schema.TABLES
ORDER BY CREATE_TIME DESC
LIMIT 1
For the specific database you're connected to:
SELECT *
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = SCHEMA()
ORDER BY CREATE_TIME DESC
LIMIT 1
Langdon
2010-01-07 13:20:38
MySql doesn't have information_schema.TABLES available in all versions
Rowland Shaw
2010-01-07 13:22:37
Your MySQL might not, but mine does, and it's in the docs... http://dev.mysql.com/doc/refman/5.0/en/information-schema.html
Langdon
2010-01-07 13:24:13
@Langdon: yup. you can akso use the `SCHEMA()` function to get the name of the current database, so `WHERE TABLE_SCHEMA = SCHEMA()`. @Rowland Shaw, this feature is supported since MySQL 5.0, generally available as of 19 october 2005
Roland Bouman
2010-01-07 13:25:24
Thanks Roland B, I updated the answer.
Langdon
2010-01-07 13:33:59