Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - query for last created table

Tags:

mysql

Is there a query that will show the last created table in a database?

like image 946
Brian Avatar asked Jan 07 '10 13:01

Brian


People also ask

How do I find the last created table in SQL?

In the Object Explorer in SQL Server Management Studio, go to the database and expand it. Under the Tables folder select the table name. Right click and select Properties from the menu. You will see the created date of the table in the General section under Description.

How do I get last table entry?

To select the last row, we can use ORDER BY clause with desc (descending) property and Limit 1. Let us first create a table and insert some records with the help of insert command. The query is as follows. After creating the above table, we will insert records with the help of insert command.

How do I see all created tables in SQL?

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.

How can I tell when a MySQL table was last updated?

SELECT UPDATE_TIME FROM information_schema. tables WHERE TABLE_SCHEMA = 'yourDatabaseName' AND TABLE_NAME = 'yourTableName'; Let us implement the following query to get the last updated time. mysql> SELECT UPDATE_TIME -> FROM information_schema.


1 Answers

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
like image 122
Langdon Avatar answered Oct 27 '22 00:10

Langdon