hba*_*042 1 mysql sql-timestamp
在 MySQL 中,我有很多列的表。如何获取所有具有时间戳数据类型的列名?我想对数据库中的所有表执行此操作。
时间戳列的数据类型可以是 TIMESTAMP 或 TIMESTAMP(6)。
输出如下所示:
table_name | column_name | data type |
-----------------------------------------
tabe01 | column01 | timestamp |
tabe02 | column03 | timestamp(6) |
tabe03 | column02 | timestamp |
tabe04 | column05 | timestamp |
Run Code Online (Sandbox Code Playgroud)
@kevin012 这样的东西适合你的目的吗?您可能需要稍微尝试一下才能使其符合您的喜好,但希望这对您有用。
select tab.table_schema as database_schema,
tab.table_name as table_name,
col.ordinal_position as column_id,
col.column_name as column_name,
col.data_type as data_type,
case when col.numeric_precision is not null
then col.numeric_precision
else col.character_maximum_length end as max_length,
case when col.datetime_precision is not null
then col.datetime_precision
when col.numeric_scale is not null
then col.numeric_scale
else 0 end as 'precision'
from information_schema.tables as tab
inner join information_schema.columns as col
on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
where tab.table_type = 'BASE TABLE'
and tab.table_schema not in ('information_schema','mysql',
'performance_schema','sys')
and col.data_type = 'timestamp'
-- uncomment line below for current database only
-- and tab.table_schema = database()
-- uncomment line below and provide specific database name
-- and tab.table_schema = 'your_database_name'
order by tab.table_name,
col.ordinal_position;
Run Code Online (Sandbox Code Playgroud)
从源修改: https: //dataedo.com/kb/query/mysql/list-table-columns-in-database
| 归档时间: |
|
| 查看次数: |
981 次 |
| 最近记录: |