views:

53

answers:

2

Hi All,

I have a need to build a schema structure to support table of contents (so the level of sections / sub-sections could change for each book or document I add)...one of my first thoughts was that I could use a recursive table to handle that. I want to make sure that my structure is normalized, so I was trying to stay away from deonormalising the table of contents data into a single table (then have to add columns when there are more sub-sections).

It doesn't seem right to build a recursive table and could be kind of ugly to populate.

Just wanted to get some thoughts on some alternate solutions or if a recursive table is ok.

Thanks,

S

A: 

When in doubt, keep it simple. Where you've a collection of similar items, e.g. employees then a table that references itself makes sense. Whilst here you can argue (quite rightly) that each item within the table is a 'section' of some form or another, unless you're comfortable with modelling the data as sections and handling the different types of sections through relationships to these entities, I would avoid the complexity of a self-referencing table and stick with a normalized approach.

Will A
Thanks for the info...appreciate it. --S
scarpacci
+2  A: 

It helps that SQL Server 2008 has both the recursive WITH clause and hierarchyid to make working with hierarchical data easier - I was pointing out to someone yesterday that MySQL doesn't have either, making things difficult...

The most important thing is to review your data - if you can normalize it to be within a single table, great. But don't shoehorn it in to fit a single table setup - if it needs more tables, then design it that way. The data & usage will show you the correct way to model things.

OMG Ponies
Thanks, I appreciate the info. The CTEs definitely make it easier to handle these situations. Thanks
scarpacci