shsql: creating a new database, table, or index

SQL database system
| Manual page for creating(a)

## CREATE

The `CREATE` command can be used to create a new table, or index.``

shsql adds the extensions CREATE STREAM and CREATE SEQUENCE which are discussed elsewhere.``

There is no CREATE DATABASE command; the project setup page describes how to create new databases.``

## CREATE TABLE

To create a new table use the `CREATE TABLE` command. Usage:

    	create table tablename ( fieldname1, .. fieldnameN )

``

shsql fields are typeless and there is no specification of `NULL` or `NOT NULL` in shsql `CREATE TABLE` statements.`` For example, to create a new table called `accounts`:

    	$ shsql "create table accounts (id, name, email, balance)"

The result is that an empty data table file (with field name header) is created in the database `data` directory.``

## CREATE INDEX

To create a new index on table field(s), use the `CREATE INDEX` command. This may also be used to rebuild an index; `CREATE INDEX` will proceed whether an index already exists or not.`` Indexes are represented as plain ascii files residing in the database `indexes` directory.`` The table can be a database table or ordinary file; indexes on temp tables aren't supported.`` `CREATE INDEX` will build indexes on the requested fields and also rebuild any existing indexes associated with the table. The `LATER` option may be used to put off the actual index building, until the next `CREATE INDEX` or `MAINTAIN` command is issued.`` shsql does not use index names.`` There may be only one index directly associated with any given field. Usage:

    	create index [type=indextype] [later] on tablename
    	( fieldname1 [orderspec], .. fieldnameN [orderspec] )

For example, to create standard ISAM indexes on the `id` and `name` fields of the accounts table illustrated above, the following command would be used.`` The result will be an index on `id`, and an index on `name`.``

    	$ shsql "create index on accounts ( id, name )"

An index type may be specified, to control the type of index(es) that will be built. Default is `standard` index. To build a different index type, use the `TYPE=` option after the word `INDEX` (whitespace is optional around the equals-sign). For example, to build a `direct` index:

    	$ shsql "create index type=direct on delinqlist ( name )"

Numeric order: Fields that will be subject to numeric comparisons such as greater than (>), less than (<), `INRANGE`, `OUTRANGE`, etc. should have indexes explicitly built for numeric order instead of alphanumeric.`` To do this, follow the field name with the attribute `ORDER=NUMERIC` (whitespace is optional around the equals-sign). This will affect only the one field.`` For example:

    	create index on stats mean order=numeric

Note: Fields that will be subject to comparisons such as `IN`, `INLIKE`, `CONTAINS`, etc.`` must have alpha indexes.. don't use `ORDER=NUMERIC` for these.``

## Notes

All `CREATE` functionality is actually carried out by shsql utility programs shsql_create, tabmaint, and buildix. Access to unix sort(1) is also required.`` The shsql bin must be in your command PATH, or else `dbbin` must be defined in your config file.``

`ORDER=NUMERIC` is incompatible with `WORD` and `COMBINEDWORD` indexes.``
Copyright Steve Grubb

Markup created by unroff 1.0, `` `` March 19, 2004.