By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
PRAGMA foreign_keys = ON;
CREATE TABLE Heap (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE CHECK(typeof(name) = 'text'),
parent INTEGER REFERENCES Heap(id),
color INTEGER CHECK(color BETWEEN 0 AND 2)
);
INSERT INTO Heap (name, parent, color) VALUES ('name1', null, 1)
INSERT INTO Heap (name, parent, color) VALUES ('name2', 1, 1)
SELECT * FROM Heap
id | name | parent | color |
---|---|---|---|
1 | name1 | null | 1 |
2 | name2 | 1 | 1 |
INSERT INTO Heap (name, parent, color) VALUES ('name3', 5, 2)
id | name | parent | color |
---|---|---|---|
1 | name1 | null | 1 |
2 | name2 | 1 | 1 |
FOREIGN KEY constraint failed
INSERT INTO Heap (name, parent, color) VALUES ('name3', null, 2)
INSERT INTO Heap (name, parent, color) VALUES ('name4', 2, 1)