Right now, I'm learning all about database design. Basically the contents of my database are brands for musical instruments. And there are two types of musical instruments which is Guitar and Bass. Now, I have stumbled upon a problem where sometimes a brand would have two types. Like for example in the table below, as you can see the ibanez is repeated twice so that it can accomodate both guitar and bass. I was advised to never repeat data in database but I haven't thought of a solution for this yet.
brandId type name image
1 Guitar Ibanez xyz.jpg
2 Bass Ibanez hyz.jpg
3 Guitar Fender abc.jpg
4 Bass Fender fgh.jpg
5 Guitar PRS yui.jpg
6 Guitar ESP mbm.jpg
7 Bass Warwick omo.jpg
When i want to display the brand images in my webpage whether its for guitar or bass, i would normally use this query in asp.net.
public List<brand> GetBrandData()
MusicStoreDBEntities obj = new MusicStoreDBEntities();
List<brand> list = new List<brand>();
list = (from g in obj.brands where g.type=="Guitar" select g).ToList();
Basically What you'll want to do in order to avoid duplicates, is store your data in multiple tables instead of one.
It seems a bit silly with data this small, but what you'll need is a table Instrument, a table Type and a table Brand that are connected with primary/foreign key relationships like the following:
And the data in your tables will look like this:
The reason why you're doing this is consistency.