开发者

Database design (normalization?)

In the following situation, what would the database design look like?

This is for some sort开发者_如何学Python of inventory system.

I want users to be able to create a item-type (lets say, a Laptop). I also want users to be able to say the serial number and MAC address must be unique. This part confuses me where to check for unique values, since I have no idea how to make a table with all items in it, with unique values..

Let's say a user creates another item-type that has no serial number or any unique fields, this means I can't build my DB with property1 till property10 fields in the database.

I also don't want to build a table for every item type, since that would involve too advanced table management in PHP.

Any suggestions on how to build this DB?


Just to clarify I understand your requirements correctly, you meant to create a table that unique rule only applies to a subset of the table instead of the entire table?

If so, I think there will be two options

  • have two tables, one with unique rules and one without OR
  • Enforce the unique rules in application level as business rules instead of database level.


If i got your question correctly , i would just do something simple and maintainable, such as :

Database design (normalization?)


you can achieve it by, assume ,table name is item,here item id is primary key.it makes easy to pick up which item you want.then while posting(inserting) serial number and mac address,you should check with php ,that there is no duplication of data.

did i got u !

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜