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;