RI Constraints Flashcards

1
Q

Example of defining RI constraint

A

CREATE TABLE Departments (
id INT PRIMARY KEY,
name VARCHAR(50)
);

CREATE TABLE Employees (
id INT PRIMARY KEY,
name VARCHAR(50),
department_id INT,
–if the PKey in Departments (parent) changes, the FKey here will change
FOREIGN KEY (department_id) REFERENCES Departments(id) ON UPDATE CASCADE
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

ON UPDATE CASCADE

A

“If the primary key in Table B (parent) changes, update the corresponding value in my foreign key column.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ON DELETE CASCADE

A

“If a row in Table B (parent) is deleted, delete my related rows automatically.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

ON UPDATE SET NULL

A

“If the primary key in Table B (parent) changes, set my foreign key column to NULL”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ON DELETE SET NULL

A

“If the primary key in Table B (parent) gets deleted, set my foreign key column to NULL”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

ON UPDATE SET DEFAULT

A

“If the primary key in Table B (parent) changes, set my foreign key column to its default value”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ON UPDATE RESTRICT

A

“If you try to update a primary key in Table B (parent) that I reference, stop the operation if it affects me”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

ON UPDATE NO ACTION

A

“If the primary key in Table B (parent) changes, do nothing immediately, but enforce integrity later if needed”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly