Advanced Search

Results 1 to 5 of 5

Thread: Why use numbers for index?

  1. #1
    Join Date
    Dec 2009
    Location
    North Carolina
    Posts
    71
    Thanks
    13
    Thanked 3 Times in 3 Posts

    Default Why use numbers for index?

    I have limited database experience and am about to try a big project, my question being what's the advantage to using numbers for the index of records rather than just making user name the primary and unique so you can always find the record by the name?

    Such as keep track of users:
    user: john
    password: john
    etc.

    Why not say select * where user='john' ?
    What's the purpose to having
    id: #
    user: john
    etc.

    Or is there any advantage?

    Thanks!
    Tim

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    an id number can be auto-incremented, so it's useful for things that need to be kept in order.

    Also, by doing so, you guarantee that you won't have two rows with the same id (e.g., you'll have #1 (john) and #2 (john) instead of john and john (which would cause problems).
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  3. #3
    Join Date
    Dec 2009
    Location
    North Carolina
    Posts
    71
    Thanks
    13
    Thanked 3 Times in 3 Posts

    Default

    If you set it to unique wouldn't that prevent this issue? If not, it would be easy to check if a row exists under john right?

    EDIT: Also you'd want to prevent there from being 2 user names John anyways because of log in, there couldn't be 2 identical user names.

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,623
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    well, consider:

    1. "UNIQUE" would prevent duplicate ids, but by throwing an error instead of solving/working around the problem.

    2. Checking if a user id exists is easy, but if when your table gets bigger, it can become time/resource-consuming.

    3. Facebook (for example) allows two people to have the same name, just like RL. IMO, using some alternate value as a username (id#, or email is a really good one) is better than telling someone "john's already taken, so you have to change your name." Unique usernames (not real names) is desirable in many cases, however, so it would depend on your application.

    One other point to consider is that a number (integer) is a lot quicker to code for/ work with than a name (string).
    We Only Torture the Folks We Don't Like (You're Probably Gonna Be Okay)
    It's a Party in the CIA

  5. #5
    Join Date
    Mar 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The following is a collection of JavaScript for computing some of the most useful business and economics index numbers.

    The primary purposes of an index number are to provide a value useful for comparing magnitudes of aggregates of related variables to each other, and to measure the changes in these magnitudes over time. Consequently, many different index numbers have been developed for special use. There are a number of particularly well-known ones, some of which are announced on public media every day. Government agencies often report time series data in the form of index numbers. For example, the consumer price index is an important economic indicator. Therefore, it is useful to understand how index numbers are constructed and how to interpret them. These index numbers are developed usually starting with base 100 that indicates a change in magnitude relative to its value at a specified point in time.

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
  •