By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
PRAGMA foreign_keys = 1;
✓
CREATE TABLE departments (
name PRIMARY KEY NOT NULL
);
✓
INSERT INTO departments VALUES ('department1')
✓
SELECT * FROM departments;
name |
---|
department1 |
CREATE TABLE tools (
id INTEGER PRIMARY KEY AUTOINCREMENT,
tool_name TEXT NOT NULL UNIQUE,
tool_price DECIMAL(5, 2),
tool_department VARCHAR(250),
FOREIGN KEY (tool_department) REFERENCES departments(name) ON DELETE CASCADE
);
✓
INSERT INTO tools VALUES (1, 'tool1', 100.0, 'department1');
✓
SELECT * FROM tools;
id |
tool_name |
tool_price |
tool_department |
---|---|---|---|
1 |
tool1 |
100 |
department1 |