MODIFY keyword with ALTER is used to modify the database of the Column in a table. It also helps to decide the nullability of a column.
Alter Table Modify Column OracleSyntax
ALTER TABLE table_name
MODIFY column_name Datatype;
- column_name is the name of the column for which we need to change the datatype.
- Datatype above describes the datatype to which we want to change the table.
- We cannot modify the column that already contains values.
Alter Table Modify Column Oracle Example
Referring to the current schema of Stu table below:
We can see that for lname the current Datatype is Varchar(with size 20). Now, we want to change this Datatype from Varchar to Char with size 20.
Alter table Stu
modify lname char(20);
Output
and we got the current schema as:
Example: Oracle Modify the column as NOT NULL
We can also describe the column lname as NOT NULL using MODIFY:
Firstly we need to give specific values to all NOT NULL values.
update stu
Set lname='not defined'
where lname is null;
Output:
Now we can Modify lname column as NOT NULL:
Alter table Stu
modify lname NOT NULL;
Output:
Now you can find the schema that is shown below: