Advantages and disadvantages of SQL GUID and auto-increment key

Source: Internet
Author: User

Our company's database is all using the GUID key, many people are accustomed to use the INT key. So, here's a summary of the two data types of the master key for a comparison.

Advantages of using the INT key:

1, need very small data storage space, only need 4 byte.

2, insert and UPDATE operations use INT for better performance than GUIDs, so using int will improve the performance of your application.

3, index and join operations, INT is the best performance.

4, easy to remember.

5, support through the function to get the latest value, such as: Scope_indentity ().

Disadvantages of using int key

1, if the operation of the table is often merged, the primary key duplication may occur.

2, the use of INT data range is limited. If there is a large amount of data, the range of values for int may be exceeded.

3, it is difficult to deal with distributed storage data tables.

Advantages of using the GUID master key:

1, it is unique.

2, there is less chance of duplication.

3, suitable for large amount of data in the insert and update operations.

4, cross-server data merging is very convenient.

Disadvantages of using the GUID master key:

1, storage space is large (in bytes), so it will take up more disk size.

2, difficult to remember. Join operation performance is lower than Int.

3. There is no built-in function to get the newly generated GUID primary key.

4. The GUID master key will be added to the other indexes on the table, thus reducing performance.

Summarize:

The advantages and disadvantages of the GUID and int two data types are listed above. I think it's recommended to use the GUID master key for large data volumes. Using int will give you the best performance.

Transferred from: http://www.cnblogs.com/zhuqil/archive/2010/12/02/1894575.html

Advantages and disadvantages of SQL GUID and auto-increment key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.