当前的现有表如下所示:
id number amount
1 123 30000.00
2 123 15000.00
3 321 45000.00
... ... ...
1000 567 75000.00
现在,我想在每个现有行中添加新列allocated_amount
,该列的默认值为amount
列。
id number amount allocated_amount
1 123 30000.00 30000.00
2 123 15000.00 15000.00
3 321 45000.00 45000.00
... ... ... ...
1000 567 75000.00 75000.00
有可能吗? Im使用MySQL工作台GUI。
它不能作为默认列。 您可以编写一个触发器并这样做,或者在MySQL5.7中添加虚拟列。
或者alter table Tab1 add allocated_amount int; --添加列更新选项卡1设置allocated_amount=金额; --设置值
虚列:alter table Table1添加allocated_amount生成的整数始终为(amount)虚;