Which statement adds a column called salary to the employees table having 100 rows,
which cannot contain null?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Explanation:
http://www.comp.nus.edu.sg/~ooibc/courses/sql/ddl_table.htm (see changing table
structures)
Correct option is C.
My table test_country has 100 rows 🙂
Example A.
alter table test_country add salary Number(8,2) NOT NULL;
ORA-01758: table must be empty to add mandatory (NOT NULL) column
Example C.
alter table test_country add salary Number(8,2) Default 0 NOT NULL;
Table altered.
C as proven by Deepak and make more sense with the existing 100 rows of data.
Actually if the column is already present and need to change means we need to use modify instead of add
alter table employees
modify salary number(8,2) not null;
So none of the option is correct
Correct answer C
Answer A comes with this error
Error report –
ORA-01758: table must be empty to add mandatory (NOT NULL) column
01758. 00000 – “table must be empty to add mandatory (NOT NULL) column”
*Cause:
*Action: