.ig >>
<STYLE TYPE="text/css">
<!--
        A:link{text-decoration:none}
        A:visited{text-decoration:none}
        A:active{text-decoration:none}
        OL,UL,P,BODY,TD,TR,TH,FORM { font-family: arial,helvetica,sans-serif;; font-size:small; color: #333333; }

        H1 { font-size: x-large; font-family: arial,helvetica,sans-serif; }
        H2 { font-size: large; font-family: arial,helvetica,sans-serif; }
        H3 { font-size: medium; font-family: arial,helvetica,sans-serif; }
        H4 { font-size: small; font-family: arial,helvetica,sans-serif; }
-->
</STYLE>
<title>shsql: alter</title>
<body bgcolor=99cc99 vlink=0000FF>
<br>
<br>
<center>
<table cellpadding=2 bgcolor=FFFFFF width=550 ><tr>
<td align=right><a href="shsql_home.html">
<img src="img/shsql.gif" border=0><br><small>SQL database system</a> &nbsp; </td></tr>
<td>
.>>

.TH alter TDH "18-MAR-2004   TDH scg@jax.org" 

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

.ig >>
<br><br><br>
.>>

.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

.ig >>
<br><br><br>
.>>

.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

.ig >>
<br><br><br>
.>>
.SH The NOMAINTAIN option
Normally an ALTER operation automatically triggers subsequenet
.ig >>
<a href="maint.html">
.>>
\0table maintenance
.ig >>
</a>
.>>
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.

.ig >>
<br><br><br>
.>>

.SH Notes
.LP
ALTER issues a 
.ig >>
<a href="tablelocking.html">
.>>
\0write-lock
.ig >>
</a>
.>>
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
.ig >>
<a href="config.html#tmpdir">
.>>
\0tmp file directory
.ig >>
</a>
.>>
called \fCalter.*\fR.

.ig >>
<br>
<br>
</td></tr>
<td align=right>
<a href="shsql_home.html">
<img src="img/shsql.gif" border=0></a><br>
<a href="Copyright.html">Copyright Steve Grubb</a> &nbsp;
</td></tr>
</table>
.>>
