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