I have a table TreeStructures wich holds structures of Trees. This table has columns ‘id, name, left, right and a foreign key TreeId’ to a table Trees with a column ‘id’ and some more information about the Tree.
Now, if ‘id’ was the only column in table Trees, would it be good to remove the table Trees and let the foreign key TreeId just be a column?
Making a new Tree would mean that I would have to check the highest value of TreeId and then increment that by one to get a new value. There’s a danger of concurrency here…
Anyway, what’s best practices in this situation?
the Tree table is a distinct entity, and deserves its own table even if the table is “all key”. There may or may not be additional columns later, but omitting this table leaves your database denormalized, which is always a potential danger to data integrity
note that the concurrency issue you’re concerned about is a no-brainer on most modern databases (use an auto-incremented identity type for the ID column), and would actually be worse without the Tree table, because you’d have to do a MAX(ID) scan on the whole leaf table