#set TITLE = "removing, renaming, or copying your indexes, fields, tables, or databases"
#include top

.SH Removing, renaming, or copying your indexes, fields, tables, or databases
.LP

One of SHSQL's advantages is that it is generally easy to move databases, clone databases,
and do other manipulations, since SHSQL databases are unix text files or directories of files.
Depending on the task, there may be an SQL-based method, a manual shell command line method, or both.

#include space

.SH Removing all indexes associated with a table
SQL method: \fCdrop index on \fItablename\fC *\fR
.LP
Manual method:
Go into the \fCindexes\fR directory and delete all files that begin 
with the table name.  For example, to remove all indexes
for table 'people': \fCrm people.*\fR

#include space

.SH Removing the index on a specific table and field
SQL method: \fCdrop index on \fItablename\fR \fIfieldname\fR
.LP
Manual method:
Go into the \fCindexes\fR directory.
Index files are named \fItablename\fC . \fIfieldname\fC . \fIilevel\fR.
Delete the index files that contain the table and field in the file name.
The \fItablename\fC.0 file requires no modification.

#include space

.SH Removing all indexes in a database
Manual method: Go into the \fCIndexes\fR directory and do: \fCrm *\fR

#include space


.SH Removing a table
SQL method: \fCdrop table \fItablename\fR
.LP
Manual method:
Go into the \fCdbtabledir\fR directory
and delete the desired table data file.
If any indexes are associated with the table, delete them also (see above).

#include space

.SH Removing a database
Manual method: To completely delete an entire database, do: \fCrm -rf\fR  on 
the project directory.  (Are you sure?)

#include space

.SH Moving or renaming a database
Manual method: rename the project directory,
then modify the project directory name in the 
#set FILE = "config.html"
#set TAG = "project config file,"
#include link
and change \fCSHSQL_DB\fR if applicable.

#include space

.SH Changing the ownership of a database
Manual method: Use \fCchown -r\fR and/or \fCchgrp -r\fR on the project directory.

#include space

.SH Copying / cloning a database
Manual method:
For example, to copy the database located in \fC/home/steve/dbproj\fR, go to 
\fC/home/steve\fR and issue the command \fCcp -r -p dbproj dbproj2\fR.
Then go into \fCdbproj2\fR and modify the config file.
Set \fCSHSQL_DB\fR to reference whichever database copy you wish.

#include space

.SH Renaming a table
Manual method:
Go into \fCdbtabledir\fR directory and rename the table data file.
If any indexes are associated with the table, rename those files
in the \fCIndexes\fR directory.
Any code that references the table by name will also require attention.

#include space

.SH Copying a table
Manual method:
Go into \fCdbtabledir\fR directory and do a \fCcp -p\fR on the table data file.

#include space

.SH Renaming a field
#set FILE = "tables.html#edit"
#set TAG = "Edit the data file"
#include link
and change the fieldname header.
If any indexes are associated with the fieldname, rename those files in the \fCIndexes\fR directory.
Any code that references the field by name will also require attention.

#include space

.SH Adding a new field to an existing table
SQL method: 
#set FILE = "alter.html"
#set TAG = "ALTER TABLE"
#include link
command.
.LP
Manual method: processing with your favorite tools.

#include space

.SH Removing a field from a table
SQL method:
#set FILE = "alter.html"
#set TAG = "ALTER TABLE"
#include link
command.
.LP
Manual method: processing with your favorite tools.

.SH Rearranging fields in a table
.LP
Process with your favorite tools.  No other file needs to be modified.

#include bottom
