Adding FOREIGN KEY constraints in Oracle tables

Source: Internet
Author: User

To add a PRIMARY KEY constraint:

ALTER TABLE ga_airline ADD CONSTRAINT pk_airline_id PRIMARY KEY (airline_id);

There are three types of foreign KEY constraints:

1. Normal FOREIGN KEY constraint (cannot delete parent table record if there is a child table reference parent table primary key)

2. Cascading foreign KEY constraint (delete the parent table record that has references, and also delete all referenced child table records)

3. Empty FOREIGN KEY constraint (you can delete the parent table record that has a reference, and the foreign key field that references the parent table's primary key in the child table is automatically set to null, but the field should allow null values)

The syntax for establishing these three foreign key constraints is as follows:

For example, there are two table parent table T_INVOICE Primary key IDs. Child tableT_INVOICE_DETAIL外键字段INVOICE_ID

1, ordinary foreign KEY constraints:

ALTER TABLE T_INVOICE_DETAIL ADD CONSTRAINT FK_INVOICE_ID FOREIGN KEY (INVOICE_ID ) REFERENCES T_INVOICE(ID); 2. Cascading FOREIGN KEY constraints: ALTER TABLE T_INVOICE_DETAIL ADD CONSTRAINT FK_INVOICE_ID FOREIGN KEY (INVOICE_ID ) REFERENCES T_INVOICE(ID) ON DELETE CASCADE ; 3, empty foreign KEY constraints: ALTER TABLE T_INVOICE_DETAIL ADD CONSTRAINT FK_INVOICE_ID FOREIGN KEY (INVOICE_ID ) REFERENCES T_INVOICE(ID) ON DELETE SET NULL ;

Adding FOREIGN KEY constraints in Oracle tables

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.