#set TITLE = "creating a new database, table, or index"
#include top

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


.ig >>
<a name=table></a>
.>>
#include space

.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>
.>>
#include space

.SH CREATE INDEX
To create a new 
#set FILE = "indexes.html"
#set TAG = "index"
#include link
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
#set FILE = "indexes.html#indextype"
#set TAG = "type of index(es)"
#include link
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.


#include space
.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
#set FILE = "config.html#dbbin"
#set TAG = "config file."
#include link
.LP
\fCORDER=NUMERIC\fR is incompatible with \fCWORD\fR and \fCCOMBINEDWORD\fR indexes.


#include bottom
