Can you add not null column to a table already containing data ?

Questions by be_viral   answers by be_viral

Showing Answers 1 - 15 of 15 Answers

gtomar

  • Aug 7th, 2008
 

Hi,

Yes you can alter table after creation for adding not null constraint.

syntax is :-

ALTER TABLE tablename

MODIFY (column name) (datatype) NOT NULL;


for eg :-

ALTER TABLE EMP

MODIFY ename VARCHAR2(10) NOT NULL


Thanks,
Gunjan




MAjay

  • Jun 6th, 2009
 

Yes


ALTER TABLE <Table Name>
MODIFY <Column Name> NOT NULL;


Ex:
ALTER TABLE scfg MODIFY scfg1 VARCHAR2(10) NOT NULL;


If you have null values in the column then you have to update all with some
default value using update script otherwise it will give you error: Null Value
Found

  Was this answer useful?  Yes

dj_dj_dj

  • Jun 8th, 2009
 

Yes you can add NOT NULL column to a table that already contains data. There would not be any error such that. But only the new records inserted would be affected.

  Was this answer useful?  Yes

neelapu

  • Jun 8th, 2009
 

NOT NULL constraint cannot be added at table level
To add the constraint you need to modify the column
Ex:-
ALTER TABLE emp MODIFY ename NOT NULL;

  Was this answer useful?  Yes

javedans

  • Jul 7th, 2009
 

1. By default you cannot add not null constraints, which already have null value in the column.
2. You need replace some dummy values to null value to meet requirement and then add constraint to that column.

Hi to all..


 We can add Not NULL column to the table . But the that column must not have null value. if so u will get an error..

ORA-02296: cannot enable (Schema_name.) - null values found

So if we want to add not null columns to existed data , we must make sure that the column has no null data..


Thanks and Regards,

S.Ravi Chythanya.

  Was this answer useful?  Yes

Yes, we can add not null column to table already containing data, provided that column should not contain null values.

If that colmn contains null values, then it is not possible to add constraint.

  Was this answer useful?  Yes

Radha

  • Jul 13th, 2011
 

Yes we can add NOT NULL constraint for the column already containing data
as:
If the data doesn't have null values then -
Alter table modify constraint ;
If the data contains null values then -
1)Here first to add the not null constraint with out
accepting the existing values (null values) by disable command init
Alter table modify constraint
not null disable;
2)Then the consrtaint will be enable with out validating the previous data which are nulls
Alter table enable novalidate constraint ;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions