使用 MySQL 中的 table 记录更改 table 添加列并设置默认值

Alter table add column and set default value using the table records in MySQL

有没有办法添加新列并设置来自 MySQL 中的 table 的默认值?

例如我有这个 table“sampleTable”

ID|    column_text|    content
1 |           bla1|     sadas|
2 |           bla2|     sadas|
3 |           bla3|     sadas|
4 |           bla4|     sadas|

然后我想执行一个添加列并使用默认值的命令 column_text。

ALTER TABLE sampleTableADD column_text_duplicate longtext DEFAULT *comming from column_text;

所以改变 table 然后 运行 一个简单的更新查询。

ALTER TABLE sampleTableADD  column_text_duplicate longtext;
UPDATE sampleTableADD SET column_text_duplicate = column_text;

但这似乎有点不必要,你为什么要2列包含相同的数据。我假设您必须至少修改某些行中的复制列!