SQL database system
 
Manual page for alter(TDH)

ALTER TABLE

ALTER TABLE is an SQL command that adds new fields to an existing table, or removes existing fields.


Adding a field

ALTER TABLE tablename ADD fieldname [nomaintain]

This will add a new field called fieldname to the table tablename. The new field will be physically located at end of record.

Example: alter table properties add watersource

Example: alter table employees add pretaxmed


Deleting a field

ALTER TABLE tablename DROP COLUMN fieldname [nomaintain]

This will remove the field called fieldname from the table tablename.

Example: alter table properties drop column remarks


The NOMAINTAIN option

Normally an ALTER operation automatically triggers subsequenet table maintenance so that indexes can be properly rebuilt. If several ALTERs are being applied to a big table, you can use the nomaintain option to skip this step to save time, however the last ALTER operation done must be allowed to do the maintenance step, otherwise indexes will be invalid and retrievals will not work properly.


Notes

ALTER issues a write-lock while working. The result is placed into a temporary file. A read-lock is set during the short time that the temp file replaces the original data file.

Removal of a dropped field is done regardless of current content.

Because ALTER changes byte locations of data fields, it renders any existing indexes invalid. By default ALTER, as its last action, will rebuild any indexes associated with the table. The NOMAINTAIN option allows this step to be omitted, if, for example, several ALTERs are being done back-to-back.

ALTER is implemented using an external program called shsql_alter.

ALTER will leave a copy of the old data file file in your tmp file directory called alter.*.


Copyright Steve Grubb  


Markup created by unroff 1.0,    March 18, 2004.