Which three actions can you perform on an existing table containing data?
A. Add a new NOT NULL column with a DEFAULT value
B. Add a new column as the table’s first column
C. Define a default value that is automatically inserted into a column containing nulls
D.Change a DATE column containing data to a NUMBER data type
E.Increase the width of a numeric column
F. Change the default value of a column
正确答案:AEF
翻译:
在包含数据的现有表中可以执行三个操作?
a.使用默认值添加一个新的非空列
b.添加新列作为表的第一列
c.定义自动插入包含空值的列的默认值
d.将包含数据的日期列更改为数字数据类型
e.增加数字列的宽度
f.更改列的默认值
实验与解析:
create table ts
(xh number(3) not null,
sr date default sysdate,
xm varchar2(10),
dz varchar2(10) default 'beijing');
insert into ts(xh,xm) values (1,'zs');
insert into ts(xh,xm) values (2,'ls');
insert into ts(xh,xm) values (3,'ww');
commit;
查询数据如下:
select * from ts;
XH SR XM DZ
1 1 2019-10-22 17:11:28 zs beijing
2 2 2019-10-22 17:11:28 ls beijing
3 3 2019-10-22 17:11:28 ww beijing
上表有数据,以下分别进行实验:
--增加一个非空列,且此列有默认值
alter table ts add (note varchar(10) default '无' not null );
select * from ts;
XH SR XM DZ NOTE
1 1 2019-10-22 17:14:55 zs beijing 无
2 2 2019-10-22 17:14:55 ls beijing 无
3 3 2019-10-22 17:14:55 ww beijing 无
所以A正确
增加的列不能作为第一列,所以B错误
insert into ts(xh) values (4);
commit;
select * from ts;
XH SR XM DZ NOTE
1 1 2019-10-22 17:14:55 zs beijing 无
2 2 2019-10-22 17:14:55 ls beijing 无
3 3 2019-10-22 17:14:55 ww beijing 无
4 4 2019-10-22 17:18:20 beijing 无
第四行第三列数据包括null,试着修改此列为默认值'WM'
alter table ts modify (xm default 'WM');
insert into ts(xh) values (5);
commit;
select * from ts;
XH SR XM DZ NOTE
1 1 2019-10-22 17:14:55 zs beijing 无
2 2 2019-10-22 17:14:55 ls beijing 无
3 3 2019-10-22 17:14:55 ww beijing 无
4 4 2019-10-22 17:18:20 beijing 无
5 5 2019-10-22 17:21:00 WM beijing 无
由此可见新插入的行默念值生效了,原空值无法改变,所以C错
SQL> alter table ts modify (SR NUMBER);
alter table ts modify (SR NUMBER)
*
第 1 行出现错误:
ORA-01439: 要更改数据类型, 则要修改的列必须为空
由此可见,D错误
将列XH长度从3改为4
SQL> alter table ts modify (xh NUMBER(4));
表已更改。
所以E正确
SQL> alter table ts modify(xh default 0);
表已更改。
SQL> alter table ts modify(note default '有');
表已更改。
更改列的默认值,没有问题,所以F正确
更多2019年oracle认证OCP考试071新题解析讨论请加入QQ群:479384490
更多2019年oracle认证OCP考试052新题解析讨论请加入QQ群:479384490
更多2019年oracle认证OCP考试053新题解析讨论请加入QQ群:479384490