June 2010
Intermediate to advanced
328 pages
7h 51m
English
The naive solution commonly shown in books and articles is to add a column parent_id. This column references another comment in the same table, and you can create a foreign key constraint to enforce this relationship. The SQL to define this table is shown next, and the entity-relationship diagram is shown in Figure 4, Adjacency list entity-relationship diagram.
| Trees/anti/adjacency-list.sql | |
| | CREATE TABLE Comments ( |
| | comment_id SERIAL PRIMARY KEY, |
| | parent_id BIGINT UNSIGNED, |
| | bug_id BIGINT UNSIGNED NOT NULL, |
| | author BIGINT UNSIGNED NOT NULL, |
| | comment_date DATETIME NOT NULL, |
| | comment TEXT NOT NULL, |
| | FOREIGN KEY (parent_id) REFERENCES Comments(comment_id), |
| | |
Read now
Unlock full access