database - How to design this tables better? -
firstly, sorry title couldn't find better one.
i have database stores devices depending on number:
|-----------|-------------|-------------| | device_id | device_name | device_type | |-----------|-------------|-------------| each device has 2 types, 3-port , 1-port , each port has specific name, example:
- device 1122 type 3-port, port names (kitchen,
living_room, bed_room). - device 1123 type 1-port, port name (boiler).
my imagination design is:
|-----------|-------------|--------|-----------|--------| + device_id | device_name | port_1 | port_2 | port_3 + |-----------|-------------|--------|-----------|--------| | 1122 | first floor | kitchen|living_room|bed_room| |-----------|-------------|--------|-----------|--------| | 1123 | second floor| boiler | null | null | |-----------|-------------|--------|-----------|--------| but design not since if had 100 device of type 1-port leave 200 fields empty. can please me create better design ?
i pasting in comment answer can mark question answered.
you break out ports separate, normalized table deviceid, port number, , port name. have 1 record each device , port combination foreign key reference main devices table. reduce empty fields , allow more 3 ports should requirements change. comes @ cost of additional table , duplication of key. space perspective may not end better. again, storage pretty cheap not sweat much.
zohar's answer more complete, not have problem if accept answer. should accept answer close question.
Comments
Post a Comment