Add not null constraint and constraint lenotnull constraint to oracle
When creating a table, add the not null constraint to the column in the following format:
Column_name data_type
[Constraint constraint_name] not null
Constraint constraint_name indicates the name specified for the constraint.
You can also add the not null constraint to the created table. In this case, you need to use the alter table... modify statement in the following format:
Alter table table_name modify column_name [constraint constraint_name] not null;
Delete not null Constraints
If you want to delete the not null constraint of the table's bruises, you can still use the alter table... modify statement in the following format:
Alter table table_name modify column_name null;
The specific operations are as follows:
SQL> create table person (
2 pid number (4) not null,
3 pname varchar2 (20 ),
4 bytes X char (2)
5 );
The table has been created.
SQL> desc person;
Is the name empty? Type
--------------------------------------------------------------------
Pid not null number (4)
PNAME VARCHAR2 (20)
CHAR (2)
SQL> alter table person modify pname not null;
The table has been changed.
SQL> desc person;
Is the name empty? Type
-------------------------------------------------------------------
Pid not null number (4)
Pname not null VARCHAR2 (20)
CHAR (2)
SQL> insert into person values (1, 'aaa', 'femal ');
One row has been created.
SQL> insert into person values (1, 'aaa', null );
One row has been created.
SQL> insert into person values (1, null, null );
Insert into person values (1, null, null )*
Row 3 has an error:
ORA-01400: cannot insert NULL ("SYSTEM". "PERSON". "PNAME ")
SQL> alter table person modify pname null;
The table has been changed.
SQL> desc person;
Is the name empty? Type
-------------------------------------------------------------------
Pid not null number (4)
PNAME VARCHAR2 (20)
CHAR (2)
SQL> insert into person values (1, null, null );
One row has been created.
SQL>