Pages

Table alterations

Instead of dropping an recreating a table we usually prefer a more conservative approach, altering the existing table, keeping the structure.

Here is how we want to add a column to the table:

alter table doughnut
add description varchar2(20);

We can even change the name of a table, maybe we want extend our business and doughnut is seen too limiting as a name, and we would like to rename the table pastry:

alter table doughnut
rename to pastry;

Or we could strip a column out of a table, if not used anymore:

alter table pastry
drop column created;

Post written while having fun reading Head First SQL

No comments:

Post a Comment