Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQL Design Question


SQL Design Question

Author
Message
TJT
TJT
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 254
Hi,

I am designing a database and would appreciate some thoughts. I am thinking about creating a Telephone table to handle (Tel, Cell, extension, fax) instead of putting it in the employee table.

Any input is appreciated. I am looking for the PROs and CONs of each.
gbritton1
gbritton1
Old Hand
Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)Old Hand (369 reputation)

Group: General Forum Members
Points: 369 Visits: 840
It's likely that there will be a 1x1 mapping between Employee and voice Telephone numbers. So, keeping them in one simple table could be OK. Fax numbers may be another thing. Also, telephone numbers can usually be kept as integers which only take up 4 bytes, though you'll need an algorithm to split them up for display into country code, NPA, NXX etc.

OTOH is there any other info you'd likely keep along with the telephone numbers? e.g. when the number is valid (start and end dates), when time of day or days of the week you can call someone at that number, etc. When things get a little more complicated, it's might be cleaner to have a telephone number table with a FK to the employee id, a number type (landline, mobile, fax, etc), and other things.

Basically, the wider a table gets, the more you should look for opportunities to normalize into two or more tables. It doesn't mean you have to do that. It's just an indication that you should look at it.

The exception would be a Data Warehouse, were denormalized tables are the norm, for faster reporting.

There's not one "correct" answer to your question. Like so many things in the DB world, "it depends".
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8527 Visits: 18128
I would suggest that you normalize your tables and have an additional table for the telephone numbers.
What would happen if an employee has more than one cell phone? Or several extensions?
If you put them on the employee table as additional columns, you'll have to add enough columns to handle them. If a new type of phone comes up, you'll need to add a new column.
With a normalized table, there's no need to do changes to the schema, just add the needed rows to it.


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
SQL is delicious
SQL is delicious
SSC Rookie
SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)SSC Rookie (49 reputation)

Group: General Forum Members
Points: 49 Visits: 174
Luis Cazares (4/25/2014)
I would suggest that you normalize your tables and have an additional table for the telephone numbers.
What would happen if an employee has more than one cell phone? Or several extensions?
If you put them on the employee table as additional columns, you'll have to add enough columns to handle them. If a new type of phone comes up, you'll need to add a new column.
With a normalized table, there's no need to do changes to the schema, just add the needed rows to it.


I agree. That's what I'd look at doing in the OP's situation.
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17585 Visits: 32262
I'd have a separate telephone table. That way you can have more than one phone number for any given person AND you can assign a phone number to more than one person. But, in order to support that second idea, you'd have to use an interim table to map between the Person table and the Phone table.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Chris Wooding
Chris Wooding
Old Hand
Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)Old Hand (333 reputation)

Group: General Forum Members
Points: 333 Visits: 935
I agree with Luis, but it does depend on how your data may expand in the future. We have a CRM application where there are several 'standard' phone numbers for contacts (fax, mobile, home, work direct, work switchboard, etc.) but we have to allow additional number types such as 'Secretary', '2nd home', 'mum' (I kid you not, that is an actual example) which are defined by the user on entry.
Steve-3_5_7_9
Steve-3_5_7_9
SSC Eights!
SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)SSC Eights! (982 reputation)

Group: General Forum Members
Points: 982 Visits: 1583
gbritton1 (4/25/2014)
It's likely that there will be a 1x1 mapping between Employee and voice Telephone numbers. So, keeping them in one simple table could be OK. Fax numbers may be another thing. Also, telephone numbers can usually be kept as integers which only take up 4 bytes, though you'll need an algorithm to split them up for display into country code, NPA, NXX etc.


Your answer conflicts with itself, as soon as you mentioned "numbers" it became a 1 to many relationship. 1 to 1 doesn't fit. If the business requirement was to only keep one telephone number per customer, then I would agree with keeping the phone # in the main table.


Steve



ErikMN
ErikMN
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 385
So to summarize:

Separate (normalized) tables:
PROS:
- Much more flexibility in assigning phone numbers to employees.

CONS:
- Slightly more complicated and slightly more costly to query

One table (denormalized):
PROS:
- Simpler queries
- Slightly faster queries

CONS:
- Little flexibility to add new numbers (requires schema change).
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17585 Visits: 32262
ErikMN (4/30/2014)
So to summarize:

CONS:
- Slightly more complicated and slightly more costly to query

One table (denormalized):
PROS:
- Slightly faster queries



Careful. It's at least partly a myth that denormalized storage is faster. It is easier to write queries against. And if the normalized storage is not enforced through checked referential constraints and/or has improper or missing indexes, it can be slower. But, normalization radically reduces the storage foot print when done correctly and this can increase performance over denormalized storage. It all comes down to how you're querying the data.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search