Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

I am Jalpesh Vadgama a Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 6 years of experience in .NET Technology.
Browse by Tags · View All
#ASP.NET 88
#DOTNET 87
BRH 79
ASP.NET 72
#.NET 52
C#.NET 48
DOTNET 44
ASP.NET 4.0 31
ASP.NET MVC 29
VisualStudio 27

Archive · View All
December 2010 16
July 2011 13
April 2011 13
April 2012 12
January 2011 12
June 2011 11
May 2011 11
May 2012 8
February 2013 7
January 2013 7

GUID Vs Int data type as primary key

Dec 1 2010 4:39PM by Jalpesh   

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.

 

 

Shout it

Tags: SQLServer, SQLServer2008Express, BRH, int.parse, Convert.ToInt32, #SQLServer, #TSQL,


Jalpesh
15 · 11% · 3478
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

6  Comments  

  • Hi Jalpesh,

    Really Good summary.

    You can add one more thing in disadvantage of GUID - If you use newid() as function to generate the GUID and you have primary key, it will increase the fregmentation and slows insert and select both.

    -Chintak.

    commented on Dec 1 2010 5:06AM
    Chintak Chhapia
    40 · 5% · 1457
  • Your conclusion is incorrect. The more data you have, the worse the decision to use a GUID is. 99.99999999% of the time, the int or bigint will be better option.

    You didn't even discuss one of the biggest problems with GUIDs which is fragmentation. Also, not only are indexes bigger, they are slower.

    But, you don't have trust me. Read what Kimberly Tripp says on the subject: http://www.sqlskills.com/BLOGS/KIMBERLY/post/GUIDs-as-PRIMARY-KEYs-andor-the-clustering-key.aspx

    commented on Dec 27 2010 12:14PM
    Robert L Davis
    1369 · 0% · 15
  • One should define "large".

    int columns can hold 2^32 unique values (-2^31 through 2^31) or about 4 billion values. Since most people don't bother with negative integers, that cuts the number of unique values in half to about 2 billion values. int uses 4 bytes of storage.

    bigint makes a good compromise between using int or GUIDs, if your only consideration is the number of unique values available. bigint has the benefit of using 8 bytes instead of GUID's 16 bytes. bigint columns can hold -2^63 through 2^63 (-9,223,372,036,854,775,808) to (9,223,372,036,854,775,807).

    If you have a single table with more than 9,223,372,036,854,775,807 rows, please contact me, I'd love to understand the use-case.

    Chintak makes a good point: NEWID() can lead to fragmentation when used with a clustered index. Two suggestions to consider: - use a non-clustered index or -use the NEWSEQUENTIALID() function instead of NEWID(). NEWSEQUENTIALID() can only be used in DEFAULT expressions.

    commented on Dec 27 2010 10:45PM
    Marc Jellinek
    97 · 2% · 546
  • @Mark Thanks for your response.

    @Robert- I am also saying same don't use GUID unless it is very much required to have

    commented on Dec 28 2010 4:33AM
    Jalpesh
    15 · 11% · 3478
  • Actually, I once had someone explain to me that the fact that GUID's "fragment" came in handy for a certain use-case. If I remember correctly, it was most notably useful because it avoided 'hot-spots' in the table where a lot of updates were happening on "the more recent rows". I guess that having the data 'all over the place' instead of grouped at the end of the table made for less 'overlap' in the locking-department and hence a better throughput of the system. (many-many small & frequent updates). Otherwise I agree that int's are a lot easier & leaner to work with.

    PS: to complete the list one could add rowversion (timestamp) as another alternative to get unique values (within the DB!!), although I'll immediately add that it's even a bigger pain to work with than GUID's =)

    commented on Dec 28 2010 9:26AM
    Roby Van Hoye
    219 · 1% · 207
  • Roby, that was back in SQL 2000 and before. Since SQL 2005, SQL is designed to take advantage of hotspots. Hotspots are good now because it increases teh chances that you are working in memory instead of reading from disk.

    Jalpesh, if you think we agree, then you typed your conclusion incorrectly. Your conclusion recommends using GUIDs for large sets of data. I am recommended the opposite viewpoint

    commented on Dec 28 2010 3:49PM
    Robert L Davis
    1369 · 0% · 15

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]