CREATE TABLE

Creates a new table.

Basic Syntax

CREATE TABLE [IF NOT EXISTS] table_name (
    column_name data_type [constraints...],
    column_name data_type [constraints...],
    ...
);

Data Types

Type Description
INTEGER 64-bit signed integer
FLOAT 64-bit floating point
TEXT Variable-length string
BOOLEAN true/false
TIMESTAMP Date and time
JSON JSON data

Column Constraints

Constraint Description
PRIMARY KEY Unique identifier, cannot be NULL
NOT NULL Column cannot contain NULL values
AUTO_INCREMENT Automatically generates sequential values

Examples

-- Basic table
CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    username TEXT NOT NULL,
    email TEXT,
    age INTEGER,
    created_at TIMESTAMP
);

-- With AUTO_INCREMENT
CREATE TABLE posts (
    id INTEGER PRIMARY KEY AUTO_INCREMENT,
    title TEXT NOT NULL,
    content TEXT,
    author_id INTEGER
);

-- With IF NOT EXISTS
CREATE TABLE IF NOT EXISTS products (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    price FLOAT NOT NULL
);

Copyright © 2025-2026 Oxibase Contributors. Gabriel Maeztu.