mysql - Constrain a columns value to a value of a different column inside the same table? -


i'm creating tree view website using databases. create 2 tables, let's call them "folder" , "file". folder can contain multiple folders , files, , files act leaf nodes - means they're "dead end" in tree if you're unfamiliar term.

the folder table contain columns:

folder_id, folder_name, folder_parent 

file contain:

file_id, file_name, file_parent 

obviously file_parent reference folder_id, creating foreign key, how make folder_parent reference folder_id?

example:

folder_name   | folder_id   | folder_parent root               1               null  cars               2                 1  planes             3                 1  bmw                4                 2  

create table folder (   folder_id int primary key,   folder_name varchar not null,   folder_parent int references folder(folder_id) ) 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -