Alter Table
Prev | Chapter 7. Features and Dialogs | Next

## Alter Table

Raise a dialog for table changing. This dialog looks quite similar like that "Create Table" one except a few things:

### Important

Sqlite ALTER TABLE command is very limited so there is no DROP COLUMN clause etc. Sqliteman handles custom ALTER TABLE with a workaround. It's strongly recommended to backup your data before dropping columns. You can lost indexes or invalidate triggers if you're not careful enough.

In this dialog you can Add and Remove table columns and set the options for new ones.

### Steps to alter table

1. Remember triggers and indexes from the original table

2. Rename the original table with temporary name

3. Create new table with original name containing new column structure

4. Perform INSERT INTO original SELECT FROM temporary

5. Drop temporary table

6. Try to recreate original indexes and triggers

When there is no request for column dropping only the ALTER TABLE ADD COLUMN is performed.

A sample log output from add one column and remove on too in one batch. You can see two failed index recreation due missing column (that dropped one):

Example 7.1. Full Alter Table Example

    Rename original table to _alter0_tags
    Creating new table: tags
    Begin Transaction
    Data Transfer
    Transaction Commit
    Dropping original table _alter0_tags
    Recreating original index/trigger
    Recreating original index/trigger
    Recreating original index/trigger
    Recreating original index/trigger
    Recreating original index/trigger
    Recreating original index/trigger
    Recreating original index/trigger
    Recreating original index/trigger
    Recreating original index/trigger (failed) table tags has no column named deviceid:
    CREATE INDEX tags_deviceid_index ON tags( deviceid )
    Recreating original index/trigger (failed) table tags has no column named deviceid:
    CREATE UNIQUE INDEX url_tag ON tags( url, deviceid )
    Columns added successfully
    Alter Table Done

Prev | Up | Next
Create Table | Contents | Import Table Data