# man > ALTER_DOMAIN(7)

---
type: CommandReference
command: ALTER DOMAIN
mode: man
section: 7
source: man-pages
---

## Quick Reference

- `ALTER DOMAIN name SET NOT NULL;` — Reject NULL values in the domain.
- `ALTER DOMAIN name DROP NOT NULL;` — Allow NULL values again.
- `ALTER DOMAIN name ADD CONSTRAINT c CHECK (expr);` — Add a check constraint.
- `ALTER DOMAIN name DROP CONSTRAINT c;` — Remove a constraint.
- `ALTER DOMAIN name RENAME CONSTRAINT old TO new;` — Rename a constraint.
- `ALTER DOMAIN name SET SCHEMA schema;` — Move domain to another schema.
- `ALTER DOMAIN name RENAME TO newname;` — Rename the domain.
- `ALTER DOMAIN name OWNER TO newowner;` — Change domain owner.

## Name

change the definition of a domain

## Synopsis

sql
ALTER DOMAIN name
    { SET DEFAULT expression | DROP DEFAULT }
ALTER DOMAIN name
    { SET | DROP } NOT NULL
ALTER DOMAIN name
    ADD domain_constraint [ NOT VALID ]
ALTER DOMAIN name
    DROP CONSTRAINT [ IF EXISTS ] constraint_name [ RESTRICT | CASCADE ]
ALTER DOMAIN name
     RENAME CONSTRAINT constraint_name TO new_constraint_name
ALTER DOMAIN name
    VALIDATE CONSTRAINT constraint_name
ALTER DOMAIN name
    OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER DOMAIN name
    RENAME TO new_name
ALTER DOMAIN name
    SET SCHEMA new_schema

where domain_constraint is:

[ CONSTRAINT constraint_name ]
{ NOT NULL | CHECK (expression) }
## Options

- `SET DEFAULT expression` — Set the default value for the domain. Only applies to subsequent `INSERT` commands, not existing rows.
- `DROP DEFAULT` — Remove the default value.
- `SET NOT NULL` — Mark the domain to reject NULL values. All existing columns using the domain must contain no nulls.
- `DROP NOT NULL` — Allow NULL values.
- `ADD domain_constraint [ NOT VALID ]` — Add a new constraint. Existing data is checked unless `NOT VALID` is used; later use `VALIDATE CONSTRAINT` to enforce. `NOT VALID` is accepted only for `CHECK` constraints.
- `DROP CONSTRAINT [ IF EXISTS ] constraint_name [ RESTRICT | CASCADE ]` — Drop a constraint. `IF EXISTS` avoids errors if the constraint does not exist. `CASCADE` drops dependent objects; `RESTRICT` (default) refuses if dependents exist.
- `RENAME CONSTRAINT constraint_name TO new_constraint_name` — Rename a constraint.
- `VALIDATE CONSTRAINT constraint_name` — Validate a constraint previously added as `NOT VALID`, checking all existing data.
- `OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }` — Change the domain owner.
- `RENAME TO new_name` — Rename the domain.
- `SET SCHEMA new_schema` — Move the domain and its constraints to a new schema.

## Examples

sql
ALTER DOMAIN zipcode SET NOT NULL;
sql
ALTER DOMAIN zipcode DROP NOT NULL;
sql
ALTER DOMAIN zipcode ADD CONSTRAINT zipchk CHECK (char_length(VALUE) = 5);
sql
ALTER DOMAIN zipcode DROP CONSTRAINT zipchk;
sql
ALTER DOMAIN zipcode RENAME CONSTRAINT zipchk TO zip_check;
sql
ALTER DOMAIN zipcode SET SCHEMA customers;
## See Also

- [CREATE DOMAIN](https://www.postgresql.org/docs/14/sql-createdomain.html)
- [DROP DOMAIN](https://www.postgresql.org/docs/14/sql-dropdomain.html)