.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: creating a new database, table, or index</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 creating a new database, table, or index TDH "19-MAR-2004   TDH scg@jax.org" 

.SH CREATE
The \fCCREATE\fR command can be used to create a new 
.ig >>
<a href="#table">
.>>
\0table,
.ig >>
</a>
.>>
or 
.ig >>
<a href="#index">
.>>
\0index.
.ig >>
</a>
.>>
.LP
\fBshsql\fR adds the extensions
.ig >>
<a href="createstream.html">
.>>
\0CREATE STREAM
.ig >>
</a>
.>>
and
.ig >>
<a href="sequences.html">
.>>
\0CREATE SEQUENCE
.ig >>
</a>
.>>
which are discussed elsewhere.
.LP
There is no CREATE DATABASE command; the
.ig >>
<a href="project_setup.html">
.>>
\0project setup page
.ig >>
</a>
.>>
describes how to create new databases.


.ig >>
<a name=table></a>
.>>
.ig >>
<br><br><br>
.>>

.SH CREATE TABLE
To create a new table use the \fCCREATE TABLE\fR command.  
Usage:
.LP
.nf
	create table \fItablename\fR ( \fIfieldname1\fC, .. \fIfieldnameN\fC )
.fi
.LP
\fBshsql\fR fields are typeless and there is no specification of \fCNULL\fR or \fCNOT NULL\fR
in \fBshsql\fR \fCCREATE TABLE\fR statements.
For example, to create a new table called \fCaccounts\fR:
.nf
	$ shsql "create table accounts (id, name, email, balance)"
.LP
The result is that 
an empty data table file (with field name header) is created in the 
database \fCdata\fR directory.

.ig >>
<a name=index></a>
.>>
.ig >>
<br><br><br>
.>>

.SH CREATE INDEX
To create a new 
.ig >>
<a href="indexes.html">
.>>
\0index
.ig >>
</a>
.>>
on table field(s), use the \fCCREATE INDEX\fR command.  
This may also be used to rebuild an index;
\fCCREATE INDEX\fR will proceed whether an index already exists or not.
Indexes are represented as plain ascii files residing in the database \fCindexes\fR directory.
The table can be a database table or ordinary file; indexes on temp tables aren't supported.
\fCCREATE INDEX\fR will build indexes on the requested fields and also rebuild any existing
indexes associated with the table.  The \fCLATER\fR option may be used to put off the
actual index building, until the next \fCCREATE INDEX\fR or \fCMAINTAIN\fR command is issued.
\fBshsql\fR does not use index names.
There may be only one index directly associated with any given field. 
Usage:
.LP
.nf
	create index [type=\fIindextype\fC] [later] on \fItablename\fC 
	( \fIfieldname1\fC [\fIorderspec\fR], .. \fIfieldnameN\fC [\fIorderspec\fR] )
.fi
.LP
For example, to create standard ISAM indexes on the \fCid\fR and \fCname\fR fields of
the accounts table illustrated above, the following command would be used.
The result will be an index on \fCid\fR, and an index on \fCname\fR.
.nf
	$ shsql "create index on accounts ( id, name )"
.fi
.LP
An \fBindex type\fR
may be specified, to control the
.ig >>
<a href="indexes.html#indextype">
.>>
\0type of index(es)
.ig >>
</a>
.>>
that will be built.  
Default is \fCstandard\fR index.  
To build a different index type, use the \fCTYPE=\fR option after the word \fCINDEX\fR
(whitespace is optional around the equals-sign).  For example, to build a \fCdirect\fR
index: 
.nf
	$ shsql "create index type=direct on delinqlist ( name )"
.fi
.LP
\fBNumeric order:\fR Fields that will be subject to numeric comparisons
such as greater than (>), less than (<), \fCINRANGE\fR, \fCOUTRANGE\fR, etc. should have 
indexes explicitly built for numeric order instead of alphanumeric.
To do this, follow the field name with the attribute \fCORDER=NUMERIC\fR (whitespace is
optional around the equals-sign).  This will affect only the one field.
For example:
.nf
	create index on stats mean order=numeric
.fi
.LP
Note: Fields that will be subject to comparisons such as \fCIN\fR, \fCINLIKE\fR, \fCCONTAINS\fR, etc.
must have alpha indexes.. don't use \fCORDER=NUMERIC\fR for these.


.ig >>
<br><br><br>
.>>
.SH Notes
.LP
All \fCCREATE\fR functionality is actually carried out by shsql utility programs 
\fBshsql_create\fR, \fBtabmaint\fR, and \fBbuildix\fR.  Access to unix \fBsort(1)\fR is
also required.
The shsql bin must be in your command PATH, or else \fCdbbin\fR must be defined in your
.ig >>
<a href="config.html#dbbin">
.>>
\0config file.
.ig >>
</a>
.>>
.LP
\fCORDER=NUMERIC\fR is incompatible with \fCWORD\fR and \fCCOMBINEDWORD\fR indexes.


.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>
.>>
