Adding a column to an UltraLite table

You can add a new column easily if the table is empty. However, if the table already holds data, you can only add a column if the column definition includes a default value or allows NULL values.

You can use either Sybase Central or execute a SQL statement (for example, Interactive SQL) to perform this task.

Sybase Central

In Sybase Central, you can perform this task while working with a selected table.

To add a new column to an UltraLite table (Sybase Central)

  1. Connect to the UltraLite database.

  2. In the left pane, double-click Tables.

  3. Double-click a table.

  4. Click the Columns tab, right-click the white space below the table and choose New » Column.

  5. Set the attributes for the new column.

  6. From the File menu, choose Save Table.

Interactive SQL

In Interactive SQL, you can only declare columns while creating or altering a table.

To add columns to a new UltraLite table (Interactive SQL)

  1. Connect to the UltraLite database.

  2. Execute a CREATE TABLE statement or ALTER TABLE, ensuring that you define columns by declaring the name, and other attributes accordingly.

    The following example creates a table for a library database to hold information about borrowed books. The default value for date_borrowed indicates that the book is borrowed on the day the entry is made. The date_returned column is NULL until the book is returned.

    CREATE TABLE borrowed_book (
       loaner_name CHAR(100)  PRIMARY KEY,
       date_borrowed          DATE NOT NULL DEFAULT CURRENT DATE,
       date_returned          DATE,
       book                   CHAR(20)
       );

    The following example modifies the customer table to now include a column for addresses that can hold up to 50 characters:

    ALTER TABLE customer
    ADD address CHAR(50);
See also