加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle 11g 添加字段default值对历史数据影响

发布时间:2020-12-12 14:31:47 所属栏目:百科 来源:网络整理
导读:创建测试表 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

创建测试表

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值会自动更新历史数据。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读