I can muddle through some SQL, but I'm having some difficulty in wrapping my head on how I would design the following to be easy to query. This is a design question so all DB servers are applicable, I should be able to adapt anything to my server.
ProductList
-----------
ProductID
CategoryID
ManufacturerID
IsHidden
...etc
Products
------------
ProductID
CategoryID
ManufacturerID
...etc
Products and other related tables are imported daily from a third-party. To make some queries easier, and quicker I consolidate some of the data from multiple tables into the ProductList table using a view. Some of these table would contain rules for hiding products, though the way I'm doing it now is crude.
Currently I have these tables
hiddenProducts
--------------
ProductID
hiddenCategories
----------------
CategoryID
hiddenMfgs
----------
ManufacturerID
With this though, I can only hide individual products, all products in a category, or all products from a manufacturer. Currently this is done with a CASE statement and LEFT OUTER JOINs to the hide tables.
I want to be able to hide by more granular rules though:
Individual Products (this table would likely not change)
Manufacturer (not likely to change, but can)
Category (not likely to change, but can)
Manufacturer within category/categories (not to difficult to add)
Manufacturer except category/categories (this is the one I'm having difficulty with)
Precedence would be this:
1. Individual Products (overrides all else)
2. ??? (the rest are dependent on each other, and the design)
I'm trying not to create an over-abundance of tables, and maybe I'm over-thinking this too much.
What would be the best way to design this? Is a CASE statement like the one above really the best way to accomplish this?
Any recommendations are welcome.
Thanks.
ProductList
-----------
ProductID
CategoryID
ManufacturerID
IsHidden
...etc
Products
------------
ProductID
CategoryID
ManufacturerID
...etc
Products and other related tables are imported daily from a third-party. To make some queries easier, and quicker I consolidate some of the data from multiple tables into the ProductList table using a view. Some of these table would contain rules for hiding products, though the way I'm doing it now is crude.
Currently I have these tables
hiddenProducts
--------------
ProductID
hiddenCategories
----------------
CategoryID
hiddenMfgs
----------
ManufacturerID
With this though, I can only hide individual products, all products in a category, or all products from a manufacturer. Currently this is done with a CASE statement and LEFT OUTER JOINs to the hide tables.
Code:
CASE
WHEN (hp.productid IS NOT NULL OR hc.categoryid IS NOT NULL OR hm.manufacturerid IS NOT NULL) THEN 1
ELSE 0
END AS ishidden,
I want to be able to hide by more granular rules though:
Individual Products (this table would likely not change)
Manufacturer (not likely to change, but can)
Category (not likely to change, but can)
Manufacturer within category/categories (not to difficult to add)
Manufacturer except category/categories (this is the one I'm having difficulty with)
Precedence would be this:
1. Individual Products (overrides all else)
2. ??? (the rest are dependent on each other, and the design)
I'm trying not to create an over-abundance of tables, and maybe I'm over-thinking this too much.
What would be the best way to design this? Is a CASE statement like the one above really the best way to accomplish this?
Any recommendations are welcome.
Thanks.