Reputation: 26
i have database tables Applicants, Batteries,Inverters and Solar Panels. the table fields on Batteries,Inverters and Solar Panels are the same,
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<table style="width:100%">
<caption>Separate Databse Table</caption>
<tr>
<th>Battery</th>
<th>Inverter</th>
<th>Solar Panel</th>
</tr>
<tr>
<td>Total Number</td>
<td>Total Number</td>
<td>Total Number</td>
</tr>
<tr>
<td>Capacity</td>
<td>Capacity</td>
<td>Capacity</td>
</tr>
<tr>
<td>Voltage</td>
<td>Voltage</td>
<td>Voltage</td>
</tr>
</table>
<hr>
<table style="width:100%">
<caption>Single Databse table</caption>
<tr>
<th>Type</th>
<th>Total Number</th>
<th>Capacity</th>
<th>Voltage</th>
</tr>
</table>
</body>
</html>
Upvotes: 0
Views: 70
Reputation: 7282
It is opinion based, but there are things which can help you decide,
If your answer to these questions is positive, thing of creating a parent object for your objects and map that to a single table. If that generalization exists, it can be predicted that there will be more relationships between new objects and all of the three, so a single table solution eases the database design and database understanding.
Upvotes: 1
Reputation: 35
Yes, You should use a single table to differentiate the fields as you have mentioned.
Type (battery,inverter,solar panel) Total number Capacity
You can add the foreign key of the applicants table in it for their relation as.
Upvotes: 2