How can I improve this database model?

可紊 提交于 2019-12-25 06:37:36

问题


I'm trying to model the relationship of dvd sales and dvd rentals to a customer. Although I dont think my transction table is correct. If anyone can let me know if I'm goin in the right direction with the design that would be great.


回答1:


Here is one way you can design this.

I am not a database expert. I have designed databases for small sized applications with few tables. I try (emphasis on try, sometimes I fail to) to be more generic as possible so I am not confined to a corner when there is a scope change.

  1. In your diagram, I noticed few things like your assumption of selling only DVDs. What happens if the shop owner starts to sell Blu-ray discs or portable game consoles. My suggestion would be to keep the design generic. So I rephrased the DVD table to Item so that the table could hold anything.

  2. I also added Item type table so that you can define what type of item it is.

  3. You transactions should be considered as a single order. A customer can place a single order that can contain a set of items they would like to purchase and also few items that they would like to rent. You wouldn't ask them to swipe the card twice, would you? Instead, create an order for the customer in the Order Header and place their line items in the Order detail table. The order detail table would also specify quantity like how many items the customer would like to purchase/rent. When they rent, the return date field would be null to begin with. When they return the item, you can go back and fill in the date by searching for the item id and customer id combination.

You can design this in n number of ways but with limited info, this is what I could come up with.

I am not stating that this is the best design. I hope this gives you some idea to take it from here and fine tune it according to your needs..




回答2:


Many retail databases model each type of transaction ("Sale of Harry Potter", "Rental of Harry Potter") as different rows in the same table. So you would have "TransactionType", and then you can have Customer->Transaction->LineItem (An instance of a transaction)->TransactionType.




回答3:


I would put all the transaction info in one table. Some fields may not be used depending on the type of transaction (P Purchase, R Rental) but so what? Disk space is cheap. The code will be simpler and run faster by having fewer tables.



来源:https://stackoverflow.com/questions/6883606/how-can-i-improve-this-database-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!