• Table with id_field VS table without id_field

    From ^Bart@gabriele1NOSPAM@hotmail.com to comp.databases.mysql on Thu Nov 7 19:14:08 2019
    From Newsgroup: comp.databases.mysql

    It could be something like "to be or not to be" lol! :D

    For example if I have tables like these:

    tags
    --------------------------
    id_tag name
    1 seaview
    2 romantic
    3 cheap

    languages
    ----------------------------
    id_language name
    1 French
    2 Italian
    3 Spanish

    tagtranslations
    -------------------------------------------------------------- id_tagtranslation FK_id_tag name FK_id_language
    1 1 Vista mare 2
    2 2 Romantico 2

    I didn't understand when in a table it could be unused id_field and when
    it should be used!

    In my db example in the tagtranslation's table I could remove id_field
    and I could have FK_id_tag+FK_id_language like primary key and name right?

    Regards.
    ^Bart
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From ^Bart@gabriele1NOSPAM@hotmail.com to comp.databases.mysql on Thu Nov 7 19:32:24 2019
    From Newsgroup: comp.databases.mysql

    I didn't understand when in a table it could be unused id_field and when
    it should be used!

    In my db example in the tagtranslation's table I could remove id_field
    and I could have FK_id_tag+FK_id_language like primary key and name right?

    I read this link https://www.quora.com/Should-every-table-in-a-database-have-an-ID-column
    and I understood when I should use ID for example when I create a user
    table where a user can change/modify his account without cancel it!

    In a translation table I can feel free to don't use an id_field because
    it's not necessary to change a translation!

    Regards.
    ^Bart
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Jerry Stuckle@jstucklex@attglobal.net to comp.databases.mysql on Thu Nov 7 15:03:50 2019
    From Newsgroup: comp.databases.mysql

    On 11/7/2019 1:32 PM, ^Bart wrote:
    I didn't understand when in a table it could be unused id_field and
    when it should be used!

    In my db example in the tagtranslation's table I could remove id_field
    and I could have FK_id_tag+FK_id_language like primary key and name
    right?

    I read this link https://www.quora.com/Should-every-table-in-a-database-have-an-ID-column
    and I understood when I should use ID for example when I create a user
    table where a user can change/modify his account without cancel it!

    In a translation table I can feel free to don't use an id_field because
    it's not necessary to change a translation!

    Regards.
    ^Bart

    No, it's not necessary in this case. However, joining tables via
    numeric columns (such as id) is much faster and more efficient than
    doing it with character strings - especially when you concatenate two
    columns.

    Plus, in the table you are joining you have to have the same columns
    (type and size), so you would have to have both columns in the table you
    want to join to, also.

    There are only very rare circumstances when I won't have an id column on
    a data table. However I will have it on a link table for a multi-multi relationship. In that case the primary key would be the two columns containing the numeric id from each table.
    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    jstucklex@attglobal.net
    ==================
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From J.O. Aho@user@example.net to comp.databases.mysql on Thu Nov 7 21:53:22 2019
    From Newsgroup: comp.databases.mysql

    On 07/11/2019 19.14, ^Bart wrote:
    It could be something like "to be or not to be" lol! :D

    For example if I have tables like these:

    tags
    --------------------------
    id_tag-a-a-a name
    1-a-a-a seaview
    2-a-a-a romantic
    3-a-a-a cheap

    languages
    ----------------------------
    id_language name
    1-a-a-a-a-a-a-a French
    2-a-a-a-a-a-a-a Italian
    3-a-a-a-a-a-a-a Spanish

    tagtranslations -------------------------------------------------------------- id_tagtranslation FK_id_tag name-a-a-a-a-a-a-a-a-a FK_id_language 1-a-a-a-a-a-a-a-a-a 1-a-a-a-a-a-a-a-a Vista mare-a-a-a 2
    2-a-a-a-a-a-a-a-a-a 2-a-a-a-a-a-a-a-a Romantico-a-a-a-a 2

    I didn't understand when in a table it could be unused id_field and when
    it should be used!

    In my db example in the tagtranslation's table I could remove id_field
    and I could have FK_id_tag+FK_id_language like primary key and name right?

    Yes, you don't need the id_tagtranslate, as you have two foreign keys
    that can be used in combination as a primary key.
    --

    //Aho
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From ^Bart@gabriele1NOSPAM@hotmail.com to comp.databases.mysql on Thu Nov 7 22:29:02 2019
    From Newsgroup: comp.databases.mysql

    No, it's not necessary in this case.a However, joining tables via

    Ok, in my case and in other cases like it it's not necessary to use id
    column but... read below...

    numeric columns (such as id) is much faster and more efficient than
    doing it with character strings - especially when you concatenate two columns.

    if the use of a column id can help the db to be much faster and more
    efficient than when you use character strings or when you concatenate
    two columns I don't understand why someone "love" to don't a column id!

    Plus, in the table you are joining you have to have the same columns
    (type and size), so you would have to have both columns in the table you want to join to, also.

    I didn't know it because I always used tables with id column!

    There are only very rare circumstances when I won't have an id column on
    a data table.a However I will have it on a link table for a multi-multi relationship.a In that case the primary key would be the two columns containing the numeric id from each table.

    Ah ok!

    Thanks for your reply! :)

    Regards.
    ^Bart
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From Jerry Stuckle@jstucklex@attglobal.net to comp.databases.mysql on Thu Nov 7 21:03:59 2019
    From Newsgroup: comp.databases.mysql

    On 11/7/2019 4:29 PM, ^Bart wrote:
    No, it's not necessary in this case.a However, joining tables via

    Ok, in my case and in other cases like it it's not necessary to use id column but... read below...

    numeric columns (such as id) is much faster and more efficient than
    doing it with character strings - especially when you concatenate two
    columns.

    if the use of a column id can help the db to be much faster and more efficient than when you use character strings or when you concatenate
    two columns I don't understand why someone "love" to don't a column id!


    I haven't talked to "them". I have no idea why they don't use a column id.

    But I do know there are a lot of people out there who have no idea what they're doing but are experts at it!


    Plus, in the table you are joining you have to have the same columns
    (type and size), so you would have to have both columns in the table
    you want to join to, also.

    I didn't know it because I always used tables with id column!

    There are only very rare circumstances when I won't have an id column
    on a data table.a However I will have it on a link table for a
    multi-multi relationship.a In that case the primary key would be the
    two columns containing the numeric id from each table.

    Ah ok!

    Thanks for your reply! :)

    Regards.
    ^Bart
    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    jstucklex@attglobal.net
    ==================
    --- Synchronet 3.21d-Linux NewsLink 1.2
  • From ^Bart@gabriele1NOSPAM@hotmail.com to comp.databases.mysql on Sat Nov 9 18:36:47 2019
    From Newsgroup: comp.databases.mysql

    Yes, you don't need the id_tagtranslate, as you have two foreign keys
    that can be used in combination as a primary key.

    Ok, but someone said this kind of table is not fast and efficient than
    if you use a numeric id...

    I think in IT area there's something like... the paper said it's better
    to do this than to do that but when you run for real your db you
    understand it's better to do the opposite of what you read on the paper!

    Regards.
    ^Bart

    --- Synchronet 3.21d-Linux NewsLink 1.2