Hi, I've got the following tables in a CMS database (SQL Server 2008) for a website:
SiteMap Page Link ========= ========= ========= SiteMapId PageId LinkId LeftNode Name Name RightNode UrlId Url -- etc -- -- etc --
- Sitemap table contains the website hierarchy using the nested set model, used primarily for generating the website navigation.
- Page table contains data for pages served by the CMS system.
- Link table contains URLs that are displayed on the site navigation, but not served by the CMS (e.g. external links to other sites).
Each SiteMap row needs to link to one row in either the Page or the Link table, and there lies the problem. What's the best way?
- Add a SiteMapId foreign key to both the Page and the Link tables - downside: allows the same SiteMap row to be referenced by more than one record (in both tables).
- Add PageId and LinkId columns to the SiteMap table - downside: one column will be redundant as it will always contain null or 0.
- Add a PageOrLinkId column to the SiteMap table and a bit field column to mark it as containing a PageId or LinkId - downside: can't add constraints to the relationships to ensure they contain valid values.
Can anyone suggest which of the above I should use, or come up with a better option? Thanks.