The database that I need to create holds data of a vehicle tracking system. So several vehicles keep sending data(about 20 parameters) to my site that stores these values in the database.
The parameters of a vehicle include the vehicle number and the hardware id as constant, the rest keep changing. So from one vehicle these two parameters are always constant.
I will have another table in this database containing the login credentials of the users and I would like to create a link between the two tables with the vehicle number(primary key) in the login table and with the vehicle number in table containing parameters.
Since the vehicle number column is redundant I cannot have it as the primary key.
So things I would like to know:
- What way can I achieve the link between tables
- Is there a good way so that I dont store this vehicle number and hardware id so many times.
- Should I be storing each vehicle’s data in separate table rather than all in one table?
P.S: This is the first time I am designing a database since I have only been a programmer all the time, so expecting good suggestions.
Putting vehicle number into the login credentials might be a very bad idea. I don’t know who your users are, but I wouldn’t want to use a site that forced me to change my login when I bought or sold a car. And what about my history? Do I lose all that?
Business logic in primary keys means bad design.
Create a surrogate primary key and use that to JOIN to the vehicle. A single user may have many vehicles, so put the foreign key from the VEHICLE table to the USER table.
Putting the vehicle data in separate table isn’t helpful if it’s 1:1. It won’t change the fact that all but two of the values are changing.
You’d reconsider this idea if your requirements include keeping a history of changes. Since you don’t mention anything about it, I’m only guessing here.
None of the questions you posed will have any effect on efficiency or application speed. You don’t give enough detail to allow someone to have must of an impact on your design. You’re guilty of pre-mature optimization at this point.