I think it was meant as a slash: 'table one or table two, depending on the query'.
Code:
CREATE TABLE positions (
id INT AUTO_INCREMENT,
name VARCHAR(128) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE people (
id INT AUTO_INCREMENT,
name VARCHAR(128) NOT NULL,
default_position_id INT,
PRIMARY KEY(id),
FOREIGN KEY(default_position_id)
REFERENCES positions(id)
ON DELETE SET NULL
);
CREATE TABLE notes (
id INT AUTO_INCREMENT,
addressee_id INT NOT NULL,
day DATE NOT NULL,
note TEXT NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY(addressee_id)
REFERENCES people(id)
ON DELETE CASCADE
);
CREATE TABLE assignments (
id INT AUTO_INCREMENT,
assignee_id INT NOT NULL,
position_id INT NOT NULL,
day DATE NOT NULL,
attendance INT NOT NULL, -- bitset, to allow easy addition/removal of checks
PRIMARY KEY(id),
FOREIGN KEY(assignee_id)
REFERENCES people(id)
ON DELETE CASCADE,
FOREIGN KEY(position_id)
REFERENCES positions(id)
ON DELETE SET NULL
);
Only one update for names. Removal of a person cascades; removal of anything else sets null. Fully normalised.
Bookmarks