Skip to content

CREATE TABLE

The CREATE TABLE command defines a new internal table within ScramDB. Data for these tables is stored and managed by the embedded Tundra storage engine.

Syntax

CREATE TABLE [IF NOT EXISTS] table_name (
column1_name data_type [constraints],
column2_name data_type [constraints],
...
[table_constraints]
);
  • IF NOT EXISTS: (Optional) Prevents an error if a table with the same name already exists.
  • table_name: The name of the table to create.
  • column_name: The name of a column.
  • data_type: The data type for the column (e.g., INT, BIGINT, VARCHAR, TEXT, FLOAT, DOUBLE, BOOLEAN, TIMESTAMP, DATE). (Note: Verify supported types against current implementation).
  • constraints: (Optional) Column-level constraints like NOT NULL, PRIMARY KEY, UNIQUE. (Note: Constraint enforcement level may vary).
  • table_constraints: (Optional) Table-level constraints like PRIMARY KEY (col1, col2), UNIQUE (col1, col2). (Note: Constraint enforcement level may vary).

Example

-- Create a simple table for users
CREATE TABLE users (
user_id BIGINT PRIMARY KEY,
username VARCHAR(100) UNIQUE NOT NULL,
email VARCHAR(255),
created_at TIMESTAMP
);
-- Create a table for products, if it doesn't exist
CREATE TABLE IF NOT EXISTS products (
product_id INT,
name TEXT NOT NULL,
price DOUBLE,
stock_count INT,
PRIMARY KEY (product_id)
);

Data inserted into tables created with CREATE TABLE will be stored efficiently within ScramDB’s internal storage. Use CREATE EXTERNAL TABLE to reference data stored in external files.