Database Design -


This is a common database question, is not related to a particular database or programming language.

I have worked some database first, but generally it just works. This time I want to plan for the future.

I have a table that stores the list of spare parts. Name, Part Number, Location etc. I also need to store what device (s) they are also applicable.

One way to do this is to create a column for each device in my spare parts table. This is a worry about how this is done in the current database if I want to add a new device in the future I have to create a new column, but it makes programming easy.

My idea is to create a separate suitability table, it will store the Part ID and Device ID, if one part applies to more than one device then it will have more than one line.

  Parts ------- Name of ID Description etc ... Parts Applicationability ------- ID Part Id Device ID Devices ------ Name of ID  

My question is is it is a legitimate way of doing this, will it provide an advantage in the original way, and are there better ways to do this?

Thanks for any answers.

I agree with Rex M's answer, this is a standard approach you do a talking on the PartsApplicability table Delete the ID column, and create the PartID / DeviceID as an overall primary key. This will ensure that your portion can not be connected to more than one device, and vice versa.


Comments

Popular posts from this blog

c++ - QtQuick: QQmlApplicationEngine failed to load component qrc:/main.qml:23 Invalid attached object assignment -

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net - getting a value of selected radiobutton in LoadViewState -