查询某一字段在数据库那些表里有值,并且生成修改该直段的sql

56 阅读1分钟

查询某一字段在那那些表含有

select * from INFORMATION_SCHEMA.columns where COLUMN_TYPE Like '%time%' and TABLE_SCHEMA='ezc';

#生成修改该直段的sql SELECT 1,
concat(
'alter table ',
table_schema, '.', table_name,
' modify column ', column_name, ' datetime(3) ',
if(is_nullable = 'YES', 'null ', 'not null '),
' default ', if(column_default IS NULL, 'null', 'CURRENT_TIMESTAMP(3)' ), ' comment ''', column_comment, ''';'
) s
from INFORMATION_SCHEMA.columns where COLUMN_TYPE Like '%time%' and TABLE_SCHEMA='ezc';