MySQL查询以获取最后创建的表名(最新的)?
您可以为此使用INFORMATIONINFORMATION_SCHEMA.TABLES概念。让我们首先创建一个表。这将是我们最近的表格-
mysql> create table DemoTable1323 -> ( -> FirstName varchar(10) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1323 values('Chris'); mysql> insert into DemoTable1323 values('David'); mysql> insert into DemoTable1323 values('Bob');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable1323;
这将产生以下输出:
+-----------+ | FirstName | +-----------+ | Chris | | David | | Bob | +-----------+ 3 rows in set (0.00 sec)
以下是查询以获取最后创建的表名称-
mysql> select table_name,create_time AS `Time` from information_schema.tables where table_schema = 'web' order by create_time desc limit 1;
这将产生以下输出:
+---------------+---------------------+ | TABLE_NAME | Time | +---------------+---------------------+ | demotable1323 | 2019-09-18 22:03:24 | +---------------+---------------------+ 1 row in set (0.02 sec)