hncys 发表于 2016-10-24 08:35:16

MySQL数据库表的主键到底是用GUID好,还是INT好?

  待补充
  
  两遍对比的文章:
  http://krow.livejournal.com/497839.html
  
  http://www.mysqlperformanceblog.com/2007/03/13/to-uuid-or-not-to-uuid/
  
  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)
)

应该改成这样吧:

CREATE TABLE Test_Guid
(
Guid uniqueidentifier not null,
TestId int not null,
TestText ntext not null,
TestDateTime datetime default getdate(),
CONSTRAINT PK_Guid PRIMARY KEY (Guid)
)
  
  另外,在使用Guid类型作为主键时,一定要记得取消主键的“聚集索引” 否则,在插入数据的时候会有严重的性能损耗。因为Guid的值不具有可预测性。
页: [1]
查看完整版本: MySQL数据库表的主键到底是用GUID好,还是INT好?