操作环境:
数据库:MySQL 5.7.20
连接工具:Navicat Premium 12.0.24
单表修改 (当前表)
表名:t_user , 字段名:create_time 和update_time ,替换后直接执行下方语句
alter table t_user modify column create_time timestamp not null default current_timestamp;
alter table t_user modify column update_time timestamp not null default current_timestamp on update current_timestamp;
多表修改(当前库中的所有表)
1、创建存储过程(循环体中:test为数据库名称,create_time和update_time是需替换的字段名称)
delimiter $$ -- mysql的名令结束符默认为(;)号,重定义结束符$$
create procedure proc_while() -- 创建存储过程,名字为proc_while
begin
declare s_tablename varchar(100); -- 定义变量名=s_tablename
declare cur_table_structure cursor -- 定义游标名 = cur_table_structure
for
select table_name from information_schema.tables where table_schema = 'test'; -- 查询指定数据库的表名
-- 在fetch语句中引用的游标位置处于结果表最后一行之后会发生02000异常,捕获后将变量值设置为null
declare continue handler for sqlstat