Oracle joins NOT NULL constraint

Source: Internet
Author: User
Tags joins

When you create a table. Add a NOT NULL constraint to the column, such as the following:
column_name Data_type
[constraint constraint_name] NOT NULL
, constraint constraint_name indicates the name specified for the constraint.
You can also add a NOT NULL constraint to a table that you have created, and you need to use the ALTER TABLE ... modify statement. Forms such as the following:
ALTER TABLE table_name MODIFY COLUMN_NAME [constraint constraint_name] NOT null;


Remove NOT NULL constraint
Suppose you need to remove the NOT NULL constraint for a laceration in the table, still using the ALTER TABLE...MODIFY statement, such as the following:
ALTER TABLE table_name MODIFY COLUMN_NAME NULL;


Detailed actions such as the following:
sql> CREATE TABLE person (
2 PID Number (4) NOT NULL,
3 pname varchar2 (20),
4 Psex char (2)
5);
The table is created.


sql> desc person;
  name                                 nbsp     Is it empty? Type
 --------------------------------------------------------------------
 pid                                       not NULL Number (4)
 pname                                              VARCHAR2 (+)
 psex       &NBSP ;                          ,         &NB Sp   CHAR (2)
sql> ALTER TABLE person modify pname not null;
The table has changed.


sql> desc person;
is the name empty?

Type
----------------------------------------- -------- ------------------
PID not NULL number (4)
PNAME not NULL VARCHAR2 (20)
Psex CHAR (2)
Sql> INSERT into the person values (1, ' aaa ', ' female ');
1 rows have been created.
Sql> INSERT into the person values (1, ' AAA ', NULL);
1 rows have been created.


sql> INSERT into person values (1,null,null);
INSERT into person values (1,null,null)                           *
Line 1th error:
ORA-01400: Cannot insert NULL ("SYSTEM". " Person "." PNAME ")
sql> ALTER TABLE person modify PNAME null;
The table has changed.


sql> desc person;
is the name empty? Type
----------------------------------------- -------- ------------------
PID not NULL number (4)
PNAME VARCHAR2 (20)
Psex CHAR (2)
sql> INSERT into person values (1,null,null);
1 rows have been created.
Sql>

Oracle joins NOT NULL constraint

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.