2.6.3. To add a not-null constraint, which cannot be written as a table constraint, use this syntax: ALTER TABLE products ALTER COLUMN product_no SET NOT NULL; The constraint will be checked immediately, so the table data must satisfy the constraint before it can be added.
All you need to do is to replace [Table] with the name of your table, [Col] with the name of your column and TYPE with the datatype of the column. Execute the command and you are allowed to use NULL values for the specified column. That is all it takes to switch between NULL and NOT NULL .
The not-null constraint in PostgreSQL ensures that a column can not contain any null value. This is a column constraint. No name can be defined to create a not-null constraint. This constraint is placed immediately after the data-type of a column.
From the fine manual: ALTER TABLE mytable ALTER COLUMN mycolumn DROP NOT NULL; There's no need to specify the type when you're just changing the nullability.
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;
More details in the manual: http://www.postgresql.org/docs/9.1/static/sql-altertable.html
Execute the command in this format
ALTER TABLE tablename ALTER COLUMN columnname SET NOT NULL;
for setting the column to not null.
Execute the command in this format:ALTER [ COLUMN ] column { SET | DROP } NOT NULL
First, Set :
ALTER TABLE person ALTER COLUMN phone DROP NOT NULL;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With