Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我更改表添加列默认值时如何更新旧行的值
类型 smallint NOT NULL DEFAULT 0
但旧行仍然为空,为什么不能自动更新为默认值?
在事务中的 alter table 语句之前发出更新语句:
update table set col = 0 where col is null
Alter table 不会更新数据,因为这不是它的工作或职责;更新是更新的工作。(我知道的唯一例外是当您更改列的类型时,在这种情况下,您可以加入 using 子句来根据需要转换数据。)