SQlite multiple table references

时间:2015-07-16 11:44:59

标签: mysql sql database sqlite

I'm not 100% sure I picked the correct title to this questions.. I've not done much work with SQlite or databases in general.

I'd have tried to google a solution if I knew what I needed to search!

So here's an example of what I want to achieve.

I have a Cars Table and a Workers Table, Cars Table is made up of carID, carName and I want to add a Workers field.. in this field I want to be able to list a number of workers that worked on the certain car.

The Workers table will be as follows - workerID, workerName, dateStarted, salary.

The idea is to list a certain car I.E carID: 1, carName: Ford Ka, workers[joe, bob, jim] and be able to access their individual properties?

Thanks, I'm not sure if this has been answered anywhere.

1 个答案:

答案 0 :(得分:0)

解决这个问题的最好/最好的方法(而不是冗余数据)是制作第三个表格,其中包含汽车和工人表的ID,例如NormalizationTable(carID,workerID,dateStarted,Salary),所以当a工人已经在汽车上工作,你添加了一个记录。该表的关键是carID,workerID。

希望这有帮助!