Using UUID as pkey in sqlite db

Discussion in 'iOS Programming' started by mraheel, Aug 2, 2011.

  1. mraheel macrumors regular

    Apr 18, 2009
    Hey guys,

    I wanted to know more about this UUID for iOS.

    I know some todo app that uses it as a task ID. perhaps suffixing it with their own tag or something.

    I wanted to know what are the advantages of using such identifiers in SQLite instead of say a normal integer based / autoincrementing primarykey.

    Apparently they are guaranteed to be unique, Can I trace a UUID to something? say date/time created or attach it to some device?

    My intention is to use it in an app that has to do with Storage purposes using Sqlite and no, its not another todo app.

    any any comment is appreciated. :)
  2. idelovski macrumors regular

    Sep 11, 2008
    I am not sure what is the real question here, but let's assume it was "what are the advantages of using such identifiers in SQLite instead of say a normal integer...?"

    Well, for example this comes handy if you need to combine records from two or more sources into a single centralized database.
  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    The UUID is unique for each device. Each device has one and only one and no other device has the same one.

    I don't see why you would use it for a sqlite db on the device.

    It is used by some to identify data sent from users to a server-based db. Some security professionals consider using the UUID in this manner to be an invasion of privacy. Many analytics and ad-servers etc do send the UUID off the device and use it as a unique identifier, behind the back of the user.
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    UUID is a Universally Unique IDentifier. It's a generated value, and changes each time it's generated. It has a statistically low probability of being generated by another device, or at another time (practically unique).

    UDID is the device's Unique Device IDentifier. It's a stored immutable value, that is always the same on each device, but different across devices (guaranteed unique). It's effectively the device's unique serial number.
  5. bbarnhart macrumors 6502a


    Jan 16, 2002
    There is no benefit in using a UUID or GUID as a key compared to an autoincrement integer.
  6. idelovski macrumors regular

    Sep 11, 2008
    Now I'm lost - are we talking about device id here or about the value returned by CFUUIDCreate() function? At first I was sure it's the later.

       CFUUIDRef    newUniqueID    = CFUUIDCreate (kCFAllocatorDefault);
       CFStringRef  newUniqueIDStr = CFUUIDCreateString (kCFAllocatorDefault, newUniqueID);
  7. mraheel thread starter macrumors regular

    Apr 18, 2009
    Thanks for the input guys.

    @PhoneyDeveloper, I got you confused, i should have stressed it. I'm referring to UUID and not UDID as chown33 pointed out.

    I know a todo app that uses this UUID with a custom 5 letter suffix.
    A UUID is assigned to each task created. Which can be shared via email with another app. They have pushnotification reminders etc.

    This app kinda inspired me to ask the utility of UUID.

    Im in the process of making similar app with enduser storage management using sqlitedb. Just wanted to make things "future proof" if and when i decide to add certain features. The presence of UUID should make things easier.

    I have no clue as to what those features might be!
  8. admanimal macrumors 68040

    Apr 22, 2005
    There is if you want the keys to be unique across devices, although I'm not sure if it's technically more efficient to use a regular integer as the primary key and have the UUID be another column that you only use when you need to find/compare things across devices.
  9. mraheel thread starter macrumors regular

    Apr 18, 2009
    Thats what I wana find out. I guess it wouldnt be efficient. But how bad could it be?
    And again, the benefit? apart from its uniqueness across devices; practically what are its applications?
  10. siggimoo macrumors newbie

    Dec 2, 2011
    This is untrue. The main point of UUIDs is the lack of a need to consult a central authority in order to generate an identifier. Each party can just make up their own whenever they need to. Sequential values, on the other hand, have to be coordinated. Now whether or not this capability is a benefit to a given system system depends on the needs of that system.

Share This Page