Skip to Content
CypherCommandsDdlAlter Column Command

Alter Column Command

In Flavius, vertices and edges are stored as tables, and their properties are stored as table columns. The ALTER COLUMN command allows you to modify the structure of these tables by renaming columns, adding new columns, or dropping existing columns.

What are Columns in Flavius?

Columns represent the properties of vertices and edges in your graph database:

  • Vertex properties: Stored as columns in vertex tables (e.g., name, age, email for a Person vertex)
  • Edge properties: Stored as columns in edge tables (e.g., weight, created_at for relationship edges)
  • Data types: Each column has a specific data type (VARCHAR, BIGINT, BOOLEAN, etc.)

Operations

Rename Column Name

Rename an existing column in a table.

Syntax

ALTER TABLE [IF EXISTS] <table_name> RENAME COLUMN [IF EXISTS] <old_column_name> TO <new_column_name>

Examples

-- Rename a column in a Person vertex table ALTER TABLE Person RENAME COLUMN first_name TO full_name -- Rename with IF EXISTS clauses for safety ALTER TABLE IF EXISTS Employee RENAME COLUMN IF EXISTS emp_id TO employee_id -- Rename a property in an edge table ALTER TABLE KNOWS RENAME COLUMN since_date TO relationship_start

Add a New Column

Add a new column to an existing table.

Syntax

ALTER TABLE [IF EXISTS] <table_name> ADD COLUMN [IF NOT EXISTS] <new_column_name> <data_type>

Examples

-- Add a new nullable column to Person table ALTER TABLE Person ADD COLUMN phone_number VARCHAR -- Add a required column with NOT NULL constraint ALTER TABLE Employee ADD COLUMN department VARCHAR -- Add column with IF NOT EXISTS for safety ALTER TABLE IF EXISTS Product ADD COLUMN IF NOT EXISTS price DOUBLE -- Add different data types ALTER TABLE User ADD COLUMN is_active BOOLEAN ALTER TABLE Order ADD COLUMN created_at TIMESTAMP ALTER TABLE Item ADD COLUMN quantity BIGINT

Drop an Existing Column

Remove a column from a table.

Syntax

ALTER TABLE [IF EXISTS] <table_name> DROP COLUMN [IF EXISTS] <column_name>

Examples

-- Drop a column from Person table ALTER TABLE Person DROP COLUMN middle_name -- Drop with IF EXISTS clauses for safety ALTER TABLE IF EXISTS Employee DROP COLUMN IF EXISTS temp_field -- Drop multiple columns (separate commands) ALTER TABLE Product DROP COLUMN old_price ALTER TABLE Product DROP COLUMN deprecated_field
Last updated on