mysql 修改字段示例
作者:
_浅墨_ | 来源:发表于
2022-11-11 15:59 被阅读0次-- 表增加字段
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,命名有误,废弃';
本文标题:mysql 修改字段示例
本文链接:https://www.haomeiwen.com/subject/uomfxdtx.html
网友评论