SQL Reference Contents

NAME

alter table - add attributes to a class

SYNOPSIS

alter table classname [ * ]
add [ column ] attname type
alter table classname [ * ]
add ( attname type )

DESCRIPTION

The alter table command causes a new attribute to be added to an existing class, classname. The new attributes and their types are specified in the same style and with the the same restrictions as in create table(l) .

In order to add an attribute to each class in an entire inheritance hierarchy, use the classname of the superclass and append a `*'. (By default, the attribute will not be added to any of the subclasses.) This should always be done when adding an attribute to a superclass. If it is not, queries on the inheritance hierarchy such as select * from super* s
will not work because the subclasses will be missing an attribute found in the superclass.

For efficiency reasons, default values for added attributes are not placed in existing instances of a class. That is, existing instances will have NULL values in the new attributes. If non-NULL values are desired, a subsequent update(l) query should be run.

You must own the class in order to change its schema.

EXAMPLE

--
-- add the date of hire to the emp class
--
alter table emp add column hiredate abstime
--
-- add a health-care number to all persons
-- (including employees, students, ...)
--
alter table person * add column health_care_id int4

SEE ALSO

create table (l) , update (l) .


Table of Contents