Apache Derby: Alter Table Statement Cheat Sheet

Created a table named Employees as shown below

ij> CREATE TABLE Employees (
   Id INT NOT NULL GENERATED ALWAYS AS IDENTITY,
   Name VARCHAR(255),
   Salary INT NOT NULL,
   Location VARCHAR(255),
   PRIMARY KEY (Id)
);

Adding a column to a Table

ALTER TABLE table_name ADD COLUMN column_name column_type;

Adding a constraint to a table

ALTER TABLE table_name ADD CONSTRAINT constraint_name constraint (column_name);

Dropping a constraint from a table

ALTER TABLE table_name DROP CONSTRAINT constraint_name;

Dropping a column from a table

ALTER TABLE table_name DROP COLUMN column_name;

Leave a Reply

Your email address will not be published. Required fields are marked *