Add not null constraint and constraint lenotnull constraint to oracle

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.