DDL — Data Definition
CREATE TABLE
CREATE TABLE table_name ( column1 TYPE, column2 TYPE, ...);Supported Types
| Type | Description | Example |
|---|---|---|
TEXT | UTF-8 string | 'hello' |
INTEGER | 64-bit signed integer | 42 |
REAL | 64-bit floating point | 3.14 |
BOOL | Boolean | TRUE, FALSE |
BLOB | Binary data | X'DEADBEEF' |
Examples
-- Basic tableCREATE TABLE users ( id TEXT, name TEXT, email TEXT, age INTEGER);
-- Create only if it doesn't existCREATE TABLE IF NOT EXISTS events ( id TEXT, type TEXT, payload TEXT, timestamp INTEGER);DROP TABLE
DROP TABLE table_name;DROP TABLE IF EXISTS table_name;Dropping a table removes its metadata from __meta/table/<name>. Row data becomes orphaned but doesn’t affect the ledger’s integrity.
ALTER TABLE
ADD COLUMN
ALTER TABLE users ADD COLUMN phone TEXT;Adds a new column to the table schema. Existing rows return NULL for the new column.
DROP COLUMN
ALTER TABLE users DROP COLUMN phone;Removes a column from the table schema. This is a metadata-only operation — existing rows are not rewritten. The dropped column is excluded from all future projections. Primary key columns cannot be dropped.
RENAME COLUMN
ALTER TABLE users RENAME COLUMN email TO email_address;Renames a column in the table schema. A column_aliases mapping is maintained so that existing rows stored with the old column name are automatically mapped to the new name on read.