Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Difference between datatype uniqueidentifier and int for a primary key?

Difference between datatype uniqueidentifier and int for a primary key?

Scheduled Pinned Locked Moved Database
asp-netsecurityquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pzn3xq
    wrote on last edited by
    #1

    I've noticed that some of the aspnet_ tables for security (e.g. aspnet_Roles) uses a primary key of a uniqueidentifer data type which is a very long number. When should someone use a primary key, where the datatype is a uniqueidentifier as opposed to int and set IsIdentity=Yes? Thanks

    C 1 Reply Last reply
    0
    • P pzn3xq

      I've noticed that some of the aspnet_ tables for security (e.g. aspnet_Roles) uses a primary key of a uniqueidentifer data type which is a very long number. When should someone use a primary key, where the datatype is a uniqueidentifier as opposed to int and set IsIdentity=Yes? Thanks

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      The main reason is because a unique identifier is unique for any database. One advantage is that if you have to merge databases then you won't class with ID values. With an int then the possibility is quite high unless you carry out a lot of work to prevent it. Another is security. Because unique identifiers are randomly generated that means a person who has one identifer cannot easily guess the next on in the sequence or find adjacent rows in the database. They could randomly guess, but with the speed of current technology they'll be there a while.

      *Developer Day Scotland - Free community conference Delegate Registration Open

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups