简体   繁体   中英

Database design (normalization?)

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

This is for some sort 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?

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

在此处输入图片说明

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.

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 !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM