Add a not null constraint on the zip column Name the constra
Add a not null constraint on the zip column. Name the constraint mem_zip_nn. Verify that the constraint was added
Solution
Not NULL Constraints
A not NULL constraint specifies that a column cannot contain a null value. This means that new rows cannot be inserted or updated unless you specify a value for this column.
You can apply the not NULL constraint when you create a column using the CREATE TABLE statement. You can also add or drop the not NULL constraint to an existing column using, respectively:
ALTER TABLE t ALTER COLUMN x SET NOT NULL
ALTER TABLE t ALTER COLUMN x DROP NOT NULL
The not NULL constraint is implicitly applied to a column when you add the PRIMARY KEY (PK) constraint. When you designate a column as a primary key, you do not need to specify the not NULL constraint.
However, if you remove the primary key constraint, the not NULL constraint still applies to the column. Use the ALTER COLUMN x DROP NOT NULL parameter of the ALTER TABLE statement to drop the not NULL constraint after dropping the primary key constraint.
For example, creating a CUSTOMERS table with ID as primary key and NOT NULL are the constraints showing that these fields can not be NULL while creating records in this table
SQL> CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ZIP VARCHAR2(5) NOT NULL
ADDRESS CHAR (25) ,
SALARY DECIMAL (18, 2),
PRIMARY KEY (ID)
);
SQL> DESC CUSTOMERS;
+---------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| ID | int(11) | NO | PRI | | |
| NAME | varchar(20) | NO | | | |
| AGE | int(11) | NO | | | |
|_zip_nn |varchar(20) |NO | | | |
| ADDRESS | char(25) | YES | | NULL | |
| SALARY | decimal(18,2) | YES | | NULL | |
+---------+---------------+------+-----+---------+-------+
Here in the above query zip column is adding _zip_nn as varchar(20) and is a notnull value. The _zip_nn constraint will add a notnull column to the table.
