I have some table with such schema (simplified):
CREATE TABLE folders(
id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
parent INT(11) UNSIGNED NOT NULL,
PRIMARY KEY (id),
INDEX FK_folders_folders_id (parent),
CONSTRAINT FK_folders_folders_id FOREIGN KEY (parent)
REFERENCES folders (id) ON DELETE CASCADE ON UPDATE CASCADE
)
1 folder can have many subfolders and can belongs to one another folder. If it's root folder then parent will contain it's own ID.
The problem is: how can I create root folder? ID is auto_increment and I can get it only after inserting a row but I cant insert row while parent is not defined. Recursion...
nullparentit's own ID when the folder is in root? Wouldn't it be better to insert a zero (0) into it?