#set TITLE = "alter"
#include top

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

#include space

.SH Adding a field
\fCALTER TABLE \fItablename\fR ADD \fIfieldname\fC  [nomaintain]
.LP
This will add a new field called \fIfieldname\fR to the table \fItablename\fR. 
The new field will be physically located at end of record.
.LP
Example: \fCalter table properties add watersource\fR
.LP
Example: \fCalter table employees add pretaxmed \fR

#include space

.SH Deleting a field
\fCALTER TABLE \fItablename\fR DROP COLUMN \fIfieldname\fC  [nomaintain]
.LP
This will remove the field called \fIfieldname\fR from the table \fItablename\fR.
.LP
Example: \fCalter table properties drop column remarks\fR

#include space
.SH The NOMAINTAIN option
Normally an ALTER operation automatically triggers subsequenet
#set FILE = maint.html
#set TAG = "table maintenance"
#include link
so that indexes can be properly rebuilt.
If several ALTERs are being applied to a big table, you can use the \fCnomaintain\fR
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.

#include space

.SH Notes
.LP
ALTER issues a 
#set FILE = "tablelocking.html"
#set TAG = "write-lock"
#include link
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.
.LP
Removal of a dropped field is done regardless of current content.
.LP
Because \fCALTER\fR changes byte locations of data fields, it renders any existing indexes invalid.
By default \fCALTER\fR, as its last action, will rebuild any indexes associated 
with the table.  The \fBNOMAINTAIN\fR option allows this step to be omitted, if, for example,
several \fCALTER\fRs are being done back-to-back.
.LP
\fCALTER\fR is implemented using an external program called \fCshsql_alter\fR.
.LP
ALTER will leave a copy of the old data file file in your
#set FILE = "config.html#tmpdir"
#set TAG = "tmp file directory"
#include link
called \fCalter.*\fR.

#include bottom
