mysql/mariadb information_schema View 创建时间

标签 mysql sql mariadb information-schema

我想查找在某个时间戳之前创建的所有表和 View 。对于表来说很简单,只需

SELECT * FROM information_schema.tables
WHERE table_type = 'TABLE' AND create_time < :ts

但对于 View 来说,事情就没那么简单了。对于 information_chema.tables 中的所有 View ,create_time 列均为空。例如

MariaDB [MYDB]> SELECT IF(create_time IS NULL, 'Null', 'Not Null') AS has_create_ts
                     , COUNT(1)
FROM information_schema.tables
WHERE table_type = 'VIEW' GROUP BY has_create_ts;
+---------------+----------+
| has_create_ts | COUNT(1) |
+---------------+----------+
| Null          |       70 |
+---------------+----------+
1 row in set, 10 warnings (0.371 sec)

并且 information_schema.views 表没有任何时间戳列。

那么我怎样才能知道 View 是何时创建的呢?或者这根本不可能。

如果重要的话数据库版本是:

MariaDB [MYDB]> SELECT VERSION();
+--------------------+
| VERSION()          |
+--------------------+
| 10.3.7-MariaDB-log |
+--------------------+
1 row in set (0.392 sec)

最佳答案

So how can I find out when a view was created? Or is it just not possible.

不,这是不可能的。

View 实际上并不包含数据,它只是由定义组成,即引用真实(物理)表中包含的数据的 SQL 语句:因此这就是INFORMATION_SCHEMA。 VIEWS 可以向您展示。

关于mysql/mariadb information_schema View 创建时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54471378/

相关文章:

php - 如何从名为 'ford' 的数据库中选择分类为 'topselers' 的所有产品?

php - MariaDB 错误与看似正确的事务 SQL

mysql - 连接到 MySQL 服务器时为 1045

php代码来匹配数据库中的列日期并显示客户数据

PHP 表单处理未发送正确的电子邮件

带有相关查询的 MySQL Having 子句不起作用

sql - 在 SQL Server 2008 中打开页面压缩时,int 与 tinyint 有关系吗?

python - MySQL - 按两列分组

sql - 递归 SQL Server 查询

mysql - 选择与 exapain 行不同的计数 (*)