Alter
Add column
ADD COLUMN
allows you to add a new column to a node/rel table. If you don’t specify a default value, the newly added column is filled with NULLs
.
Column names must be unique within a node/relationship table.
For example, consider that you try to run the following command to add a column age
, but it
already exists in the User
table:
The query will raise the following exception:
The following query adds a new column with the default value NULL
to the User table.
You can also specify the default value of the added column.
Add column if not exists
If the given column name already exists in the table, Kùzu throws an exception when you try to create it.
To avoid the exception being raised, use the IF NOT EXISTS
clause. This tells Kùzu to do nothing when
the given column name already exists in the table.
Example:
This query tells Kùzu to only create the grade
column if it doesn’t exist.
The same applies to relationship tables.
Drop column
DROP COLUMN
allows you to remove a column from a table.
The following query drops the age column from the User table.
Drop column if exists
If the given column name does not exists in the table, Kùzu throws an exception when you try to drop it.
To avoid the exception being raised, use the IF EXISTS
clause. This tells Kùzu to do nothing when
the given column name does not exists in the table.
Example:
This query tells Kùzu to only drop the grade
column if it exists.
The same applies to relationship tables.
Rename table
RENAME TABLE
allows the user to rename a table.
The following query renames table User to Student.
Rename column
RENAME COLUMN
allows the user to rename a column of a table.
The following query renames the age column to grade.
Comment on a table
COMMENT ON
allows you to add comments to a table.
The following query adds a comment to User
table.
Comments can be extracted through SHOW_TABLES()
function. See CALL for more information.