SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Mo Money's Avatar
    Join Date
    Nov 2002
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Do you need an auto-increment id field?

    I am quite good with php, and have made some cool apps, however, I have always made an id/auto-increment/unsigned/notnull/primary key field to start with all my tables just as a habit, and ive used that field before, but is it necessary? And, do I need a primary key? what does defining a field as primary actually do? Also, I know what happens when you make a field unique, but what is index?
    AbcArcade.com - free internet games!

  2. #2
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You set up primary keys and indexes to allow faster sql querying. Auto-Increment is almost always needed, to make each data row unique. You could also use a TIME STAMP for that however.

  3. #3
    SitePoint Addict Mo Money's Avatar
    Join Date
    Nov 2002
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well wouldnt each data row always be unique, unless you added all the same info as one?
    AbcArcade.com - free internet games!

  4. #4
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How would you access a row then ? Data rows have to differ on at least one field, which would be the auto-incremented primary key.

  5. #5
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DarkAngelBGE
    Auto-Increment is almost always needed, to make each data row unique.
    Nope.
    Not always needed, but it's a very convenient way of getting unique values.
    If you have a table containing names, for example, people can have same name, same address etc, i.e. could be really difficult to find the property that is different (OK, date of birth can be used...).

    SQL by Design: How to Choose a Primary Key


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •