Oracle foreign key constraint child table, parent table, oracle Constraint

Source: Internet
Author: User

Oracle foreign key constraint child table, parent table, oracle Constraint

Create table employees (
Employee_id NUMBER (6 ),
Last_name VARCHAR2 (25) not null,
Email VARCHAR2 (25 ),
Salary NUMBER (8, 2 ),
Commission_pct NUMBER (2, 2 ),
Hire_date date not null,
...
Department_id NUMBER (4 ),
CONSTRAINT emp_dept_fk foreign key (department_id)
REFERENCES parameters (department_id ),
CONSTRAINT emp_email_uk UNIQUE (email ));

 

Foreign key: indicates the column in the child table at the table level.
REFERENCES: identifies columns in the parent table
On delete cascade: When a column in the parent table is deleted, the corresponding column in the child table is also deleted.
On delete set null: the columns in the subtable are empty.


Oracle foreign key constraints

Refer:
Alter table titles
ADD
CONSTRAINT FK_pub_id foreign key (pub_id) REFERENCES publishers (pub_id)

CONSTRAINT FK_pub_id foreign key (pub_id)
-- Pub_id fields in the subtable
REFERENCES publishers (pub_id)
-- Pub_id fields in the parent table

Generally, the same name is used. It can be different.

How to delete a table with a primary foreign key relationship in oracle

Delete the child table first and then the parent table. If the two tables have primary and foreign key constraints, drop table tablename cascade constraints.

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.