Hi Guys, I'm thinking about the best way to store warranties about
products and I thought to create:
warrantytypes
-------------------------------------
warrantytype_id name
1-a-a-a-a-a-a-a 12 Months
2-a-a-a-a-a-a-a 24 Months
3-a-a-a-a-a-a-a 6 Months
products
-----------------------------------
product_id name-a-a-a-a-a-a warranty start warrantytype_id extendedwarranty 1-a-a-a-a-a-a Samsung S2 01/01/2020-a-a-a-a 1-a-a-a-a-a-a-a-a-a-a-a-a 3 2-a-a-a-a-a-a Samsung S4 01/02/2020-a-a-a-a 1-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a 3
2-a-a-a-a-a-a Samsung S3 30/12/2019-a-a-a-a 2-a-a-a-a-a-a-a-a-a-a-a-a-a-a 3
Extendedwarranty is linked to warrantytype_id, now I should understand
if it could be a good idea to add a field in products table named "expiredwarrantyday" to set if a product is out of warranty.
Why I thought to create a specific field about expiredwarrantyday?
Because I think I could add a code to calculate every day if a product
is out of warranty (expiredwarrantyday > today) and I could do a
"simple" query to this column to understand in a fast way how many
products are out of warranty!
It could be a good idea also to set a count down about warranty (for
example 10 days, one month, etc.) before the expired day but now I'd
like to know what do you think about it!
Do you think I could create another field named expiredwarranty (yes/no, 0/1) to be more fast to calculate what products are out of warranty? I
could run a script to calculate it every day...
If you only looking at the length, then just have a warranty length, not really need of a separate table for that.
Depends on how often you need that values, you can always use TIMESTAMPADD(MONTH, warranty_length, warranty_start)
, but of course if you need to make more advanced queries and need it indexed, then maybe better to store the value from start.
That you show with timestampadd + datediff, no need to make unneeded
table updates.
A bit showing if a product still has warranty can be good, then you can exclude those already passed when you are looking for how many days it's left until the warranty expires.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 63 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 492975:36:16 |
| Calls: | 840 |
| Files: | 1,301 |
| D/L today: |
16 files (28,385K bytes) |
| Messages: | 264,959 |