zoukankan      html  css  js  c++  java
  • FW: GUID Vs Int data type as primary key

    Recently one of my friend ask me when I should go for GUID and When I should go for Int as primary key in table. So decided to write a blog post for it. Here are advantages and disadvantage of the GUID and INT. 

    INT Data Type:

    Advantages:

    1. Its required small space in terms of the storage it will only allocates 4 bytes to store data.
    2. Insert and update performance will be faster then the GUID. It will increase the performance of the application.
    3. Easy to index and Join will give best performance with the integer.
    4. Easy to understand and remember
    5. Support of function that will give last value generated like Scope_Indentity()

    Disadvantages:

    1. If you are going to merge table frequently then there may be a chance to duplicated primary key.
    2. Limited range of uniqueness if you are going to store lots of data then it may be chance to run out of storage for INT data type.
    3. Hard to work with distributed tables.

    GUID Data Type:

    Advantages:

    1. It is unique for the current domains. For primary key is uniquely identifies the table.
    2. Less chances of for duplication.
    3. Suitable for inserting and updating large amount of data.
    4. Easy for merging data across servers.

    Disadvantages:

    1. Bigger storage size (16bytes) will occupy more disk size then integer.
    2. Hard to remember and lower performance with Join then integer.
    3. Don’t have function to get last uniquely generated primary key.
    4. A GUID primary Key will added to all the other indexes on tables. So it will decrease the performance.

    Conclusion:

    From above the advantages and disadvantages we can conclude that if you are having very large amount of data in table then go for the GUID as primary key in database. Otherwise INT will give best performance. Hope this will help you. Please post your comment as your opinion.

    FW: http://beyondrelational.com/blogs/jalpesh/archive/2010/12/01/guid-vs-int-data-type-as-primary-key.aspx?utm_source=brnewsletter&utm_medium=email&utm_campaign=2010Dec28

  • 相关阅读:
    结婚电子
    ASP.NET 5简介
    定位500错误!
    Web项目
    JS编程
    CQRS 示例
    领域驱动设计的面向服务架构
    Oracle免费的便捷Web应用开发框架
    ThreadLocal是否会引发内存泄露的分析 good
    应用的代码没有用新的类库来进行编译(转)
  • 原文地址:https://www.cnblogs.com/aot/p/1925677.html
Copyright © 2011-2022 走看看