Skip to content

Instantly share code, notes, and snippets.

@dayfuaim
dayfuaim / closure_table.md
Created June 8, 2016 20:18
Persistent tree structure using closure table in MySQL

Using closure tables to manage hierarchical relations in MySQL

Create DB tables

Create a table to represent tree nodes.

CREATE TABLE `tree_node` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `data_body` text,

node_deleted datetime DEFAULT NULL,