PostgreSQL -How to Drop a NOT NULL Constraint
To drop a NOT NULL
constraint from an existing column in a PostgreSQL table, you can use the ALTER TABLE
statement with the ALTER COLUMN
clause. Here’s the basic syntax:
ALTER TABLE table_name ALTER COLUMN column_name DROP NOT NULL;
where table_name
is the name of the table containing the column and column_name
is the name of the column from which you want to remove the NOT NULL
constraint.
Here’s an example of how to use this syntax to remove a NOT NULL
constraint from an existing column:
ALTER TABLE users ALTER COLUMN email DROP NOT NULL;
After executing this SQL statement, the “email” column in the “users” table will no longer have the NOT NULL
constraint, and you will be able to insert NULL values into that column if necessary.