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.
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)
Connect to the UltraLite database.
In the left pane, double-click Tables.
Double-click a table.
Click the Columns tab, right-click the white space below the table and choose New » Column.
Set the attributes for the new column.
From the File menu, choose Save Table.
In Interactive SQL, you can only declare columns while creating or altering a table.
To add columns to a new UltraLite table (Interactive SQL)
Connect to the UltraLite database.
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); |
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |