-- 表增加字段
ALTER TABLE test_user
ADD COLUMN user_id bigint not null default 0 comment '主表ID,外键关联' after main_id;
-- 表迁移数据
update test_user set user_id=main_id ;
-- 删除外键约束
ALTER TABLE test_user drop foreign key FK_Reference_44;
ALTER TABLE test_user DROP INDEX FK_Reference_44;
-- 增加外键约束
alter table test_user
add constraint FK_Reference_44 foreign key (user_id)
references biz_threeinone_test_situation (id) on delete restrict on update restrict;
-- 修改原字段备注
alter table test_user
modify column main_id bigint comment '对应主表ID,命名有误,废弃';
网友评论