Ankit
Ankit

Reputation: 1105

Any better way to design this Database structure

I have a product table which stores the information of a product. I have Only one Reference Product which have the same properties as of a product.

My doubt is what is the best way to store the information of Reference Product

Case1: Have a Reference_Flag in the Product table.

PRODUCT
Product_ID: Long
ReferenceFlag: Boolean

Clean way however...

Disadvantage:

1) As per the requirements only one reference product is possible, however this DB structure allows more than one.

2) As there could be only one reference product. I have to unnecssarly set Reference_Flag to 0 for other products in my table. Therefore as the data increases, memory is not used properly (Can't say whether it is a valid case or not)


Case2: Have a seperate table which stores only Reference product.

PRODUCT
Product_ID: Long

REFERENCE_PRODUCT
Ref_ID: Long
Product_ID: Long

In the REFERNCE_PRODUCT table I will have only one row. It will solve the problem of memory utilization and I can restrict the table to have only one row.

However now I have two tables.


Which way is better or is there any other way to achieve this?

Upvotes: 0

Views: 40

Answers (1)

deyhle
deyhle

Reputation: 473

Why not simply use the product with id=0 (or similar) as reference product?

Upvotes: 1

Related Questions