Five types of Oracle Constraints

Source: Internet
Author: User

1Syntax

1.1Row-Level Definition

 

1.2Table-Level Definition

 

 

 

2NOT NULL

Row-level definition only.

SQL> create table tn0 (a number (4) not null, B varchar2 (20 ));

SQL> create table tn1 (a number (4) constraint nn_tn1_a not null, B varchar2 (20 ));

3Unique

SQL> create table tu0 (a number (4) unique, B varchar2 (20 ));

SQL> create table tu1 (a number (4) constraint u_tu1_a unique, B varchar2 (20 ));

SQL> create table tu2 (a number (4), B varchar2 (20 ),Constraint u_tu2_a unique ());

SQL> create table tu3 (a number (4), B varchar2 (20 ),Constraint u_tu3_a unique (a, B ));

4Primary Key

SQL> create table t0 (a number (4) primary key, B varchar2 (20 ));

SQL> create table t1 (a number (4), B varchar2 (20), primary key ());

SQL> create table t2 (a number (4) constraint pk_t2 primary key, B varchar2 (20 ));

SQL> create table t3 (a number (4), B varchar2 (20), constraint pk_t3 primary key ());

SQL> create table t4 (a number (4), B varchar2 (20), constraint pk_t4 primary key (a, B ));

5Foreign key

SQL> create table tf_p (a number (4) primary key, B varchar2 (20 ));

SQL> insert into tf_p values (1, 'A ');

SQL> insert into tf_p values (2, 'bb ');

SQL> insert into tf_p values (3, 'cc ');

SQL> create table tf_s (a number (4) constraint fk_tf_sa_ref_tf_pa references tf_p, c varchar2 (20 ));

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.