我想向表中添加一個布爾列,并為新創建的行設定默認值為 false,但所有現有行都應設定為 true。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
首先更改表并將列添加為
alter table table_name add column column_name boolean default false;
然后將該列的值更新為
update table_name set column_name=true;
uj5u.com熱心網友回復:
一個簡化的測驗來演示。
create table test ( id int primary key ); insert into test (id) values (1), (2), (3);
alter table test add column truth boolean default false; update test set truth = true;
insert into test (id) values (4), (5);
select * from test;編號 | 真相 -: | :---- 1 | 噸 2 | 噸 3 | 噸 4 | F 5 | F
db<>在這里擺弄
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/415498.html
標籤:
上一篇:永遠不應該顯示第一行結果
