oraclealter

Add a column, with a default value, to an existing table in oracle


I created a table named- books and have a column in that by the title 'color' . Initially I have null values in the column 'color'. Now, when I run the following query :

alter table books modify color default 'blue';  

schema is formed but on doing select *from books , all the values in column color are still null. What would be the correct query to fire?

here is the link: http://sqlfiddle.com/#!4/f4210/1


Solution

  • Of course. Alter table just changes the table structure but not the content. New entries will get the default.

    To update the existing values run a sql-update query like:

    update books set color='blue' where colore is null;