tags:

views:

47

answers:

1

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
MySql doesn't have information_schema.TABLES available in all versions
Rowland Shaw
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
@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
Thanks Roland B, I updated the answer.
Langdon