数码资讯
oracle 11g 添加字段default值对历史数据影响
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
创建测试表
SQL> create table test_default
2 (id number,3 comm varchar2(10));
Table created
插入测试数据
SQL>SQL> insert into test_default values (1,'a');
1 row inserted
SQL> insert into test_default values (2,'b');
1 row inserted
SQL> insert into test_default values (3,'c');
1 row inserted
SQL> commit;
Commit complete
查询
SQL> select * from test_default;
ID COMM
---------- ----------
1 a
2 b
3 c
给表添加新的字段,带默认值0,不是not null
SQL> alter table test_default add new_col varchar2(2) default '0';Table altered
再次查询
SQL> select * from test_default;
ID COMM NEW_COL
---------- ---------- -------
1 a 0
2 b 0
3 c 0
SQL>
结论,oracle11g中给表添加字段带default值会自动更新历史数据。
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。