SQL Design Question

  • 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.

  • 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".

  • 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
  • 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.

  • 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 2022 Query Performance Tuning, 6th Edition and SQL Server Execution Plans, 3rd Edition
    Product Evangelist for Red Gate Software

  • 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.

  • 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

  • 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).

  • 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 2022 Query Performance Tuning, 6th Edition and SQL Server Execution Plans, 3rd Edition
    Product Evangelist for Red Gate Software

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply