ORACLE:PK,FK, joint primary key, Notnull constraint detailed ____oracle

Source: Internet
Author: User

Pk: Primary key, cannot repeat, non-empty

Fk: Foreign key, reference to another table PK, you can repeat.

Union PRIMARY key: a 2-table PK is referenced as the primary key for this table.

Application Example: Build three tables, increase the constraint

A table : CREATE TABLE Student (
s_id VARCHAR2 (10),
Name VARCHAR2 (10)
)
Tablespace MySpace

CREATE TABLE Couse (
c_id VARCHAR2 (10),
Name VARCHAR2 (10)
)
Tablespace MySpace

CREATE TABLE SC (
s_id VARCHAR2 (10),
c_id VARCHAR2 (10),
S_name VARCHAR2 (10),
C_name VARCHAR2 (10)
)
Tablespace MySpace

Two increases primary key constraints, joint primary KEY constraints:

ALTER TABLE STUDENT add primary key (S_ID)
ALTER TABLE couse add constraint C_PK primary key (C_ID)
ALTER TABLE SC add constraint sc_id primary key (S_ID,C_ID)

Three adds a foreign key to the table SC and references the student and couse table s_id,c_id, and through on DELETE cascade specifies that the reference behavior is a cascading deletion
ALTER TABLE SC add constraint SC_FK foreign key (s_id) references student (s_id) on DELETE cascade;
ALTER TABLE SC add constraint sc_f foreign key (c_id) references couse (c_id) on DELETE cascade;

Iv. increasing non-null constraints

Three add non-null constraints to the table
ALTER TABLE student modify s_id NOT null;
ALTER TABLE couse modify C_ID NOT null;

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.