Use GUID master key and int master key performance Comparison

Source: Internet
Author: User
Tags comparison datetime getdate

In the design of the database, we often use the GUID or int to make the key, according to the knowledge has always felt the INT master key efficiency is high, but did not do careful testing can not

Explain the truth. I happened to be in the process of optimizing the database today, so I did some testing.

Test environment:

Desktop computer Pentiun (R) 4 Cpu 3.06GHz

Win XP Professional

1.5G DDR RAM

SQL Server 2005-person edition

Test process:

Create Test Database First

1. Create Test_guid table, create Test_int table

Code

-------------------------------------------
--创建Test_Guid表
---------------------------------------------
USE  Test
GO
IF OBJECT_ID('Test_Guid', 'U') IS NOT NULL
   DROP TABLE Test_Guid
GO
CREATE TABLE Test_Guid
(
     Guid varchar(50) not null,
     TestId int not null,
     TestText ntext not null,
     TestDateTime datetime default getdate(),
     CONSTRAINT PK_Guid PRIMARY KEY (Guid)
)
GO
---------------------------------------------
--创建Test_Int表
---------------------------------------------
USE  Test
GO
IF OBJECT_ID('Test_Int', 'U') IS NOT NULL
   DROP TABLE Test_Int
GO
CREATE TABLE Test_Int
(
     Id int not null identity(1,1),
     TestId int not null,
     TestText ntext not null,
     TestDateTime datetime default getdate(),
     CONSTRAINT PK_Id PRIMARY KEY (Id)
)
GO

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.