postgresql alter column not null code example

Example 1: postgres add not null to existing column

ALTER TABLE table_name ALTER COLUMN column_name SET NOT NULL;

Example 2: postgresql change column to not null

-- To change a column to NOT NULL:
ALTER TABLE products ALTER COLUMN product_no SET NOT NULL;

Example 3: postgresql add not null constraint

alter table users alter column email set not null;

Example 4: postgresql alter column nullable

-- To change a column to nullable
ALTER TABLE mytable ALTER COLUMN mycolumn DROP NOT NULL;

Tags:

Sql Example