snippetsqlMinor
How to design this simple DB?
Viewed 0 times
thisdesignsimplehow
Problem
How to design this simple DB?
I need to add some things to a DB I use to keep track of servers.
Table looks something like this.
I want to add a table called Updates. It should look something like this:
What is the best way to "link" these tables? I need everything in the Name field in Matrix to be in the Updates table as well. I'm a fundamental noob when it comes to databases, so I need some 101 help with this.
I have some triggers set up for another table that keeps track of other information and that works very well... I could just add more triggers for the table I am wanting to create... but I'm not sure if that's the best method.
What would you do?
EDIT: I want the Name field from Updates to always be an exact replica of what is in Matrix.
I need to add some things to a DB I use to keep track of servers.
Table looks something like this.
Matrix
| Name | Description | Etc | Etc |
------------------------------------------------
| Server01 | First Server | Data | Data |I want to add a table called Updates. It should look something like this:
Updates
| Name | Q1 Updates | Q2 Updates | Q3 Updates |
------------------------------------------------------
| Server01 | Done | Incomplete | Incomplete |What is the best way to "link" these tables? I need everything in the Name field in Matrix to be in the Updates table as well. I'm a fundamental noob when it comes to databases, so I need some 101 help with this.
I have some triggers set up for another table that keeps track of other information and that works very well... I could just add more triggers for the table I am wanting to create... but I'm not sure if that's the best method.
What would you do?
EDIT: I want the Name field from Updates to always be an exact replica of what is in Matrix.
Solution
Based on what you've got here, it looks like you should be able to JOIN Matrix and Updates together based-on the "Name" field. If you wanted to see all servers from Matrix that had updates, you could to something like this:
That's based-on a few assumptions:
"What would you do?"
If it were me, I would create an Updates table that looked something like this:
Row data would look like:
It would have a composite (primary) key of Name and TimeFrame to ensure uniqueness (because in this scenario, "Name" will be repeated).
The advantage here, is that if your time frame for updates is altered/increased at any point (ex: if you start doing updates every 2 months, instead of quarterly) you have the flexibility of adding more updates without having to add a column to the Updates table. Of course, I'm saying that without knowing what the rest of the fields on Updates are, so maybe that wouldn't make sense. Or there could be other opportunities for normalization/optimization as well.
SELECT m.Name, m.Description, u.*
FROM Matrix m
INNER JOIN Updates u ON u.Name = m.Name;That's based-on a few assumptions:
- "Name" is your primary key in both tables.
- "Name" is unique in the Updates table (no server would have more than one entry).
"What would you do?"
If it were me, I would create an Updates table that looked something like this:
table: Updates
Name varchar(16)
TimeFrame varchar(3)
Status varchar(10)Row data would look like:
name TimeFrame Status
Server01 Q1 Done
Server01 Q2 Incomplete
Server01 Q3 IncompleteIt would have a composite (primary) key of Name and TimeFrame to ensure uniqueness (because in this scenario, "Name" will be repeated).
The advantage here, is that if your time frame for updates is altered/increased at any point (ex: if you start doing updates every 2 months, instead of quarterly) you have the flexibility of adding more updates without having to add a column to the Updates table. Of course, I'm saying that without knowing what the rest of the fields on Updates are, so maybe that wouldn't make sense. Or there could be other opportunities for normalization/optimization as well.
Code Snippets
SELECT m.Name, m.Description, u.*
FROM Matrix m
INNER JOIN Updates u ON u.Name = m.Name;table: Updates
Name varchar(16)
TimeFrame varchar(3)
Status varchar(10)name TimeFrame Status
Server01 Q1 Done
Server01 Q2 Incomplete
Server01 Q3 IncompleteContext
StackExchange Database Administrators Q#9782, answer score: 3
Revisions (0)
No revisions yet.