MySQL数据库表的主键到底是用GUID好,还是INT好?
2011-12-29 18:00
316 查看
MySQLHTML
待补充
两遍对比的文章:
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的值不具有可预测性。
待补充
两遍对比的文章:
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的值不具有可预测性。
相关文章推荐
- 数据库主键设计-用GUID还是Int(int32,int64)做主键(primaryKey)
- GUID和INT两种数据类型做主键的比较
- GUID和INT两种数据类型做主键的比较
- 数据库主键用 int自增序列 还是 GUID
- GUID和INT两种数据类型做主键的比较
- 关于char强制转换成int到底是用0还是用1补位的猜想与检验
- GUID和INT两种数据类型做主键的比较
- GUID和INT自增做主键的测试
- MySql中测试GUID 与Int自增主键 性能对比 总结适用场景
- 关于SQL主键用int还是varchar类型的一个小测试
- asp.net MVC Model 类的主键 int类型、string类型、GUID类型。
- 数据库 GUID vs INT 作为主键的性能辨析
- int 和guid做主键的时候性能的区别
- 数据库主键到底是用自增长(INT)好还是UUID好?
- 关于SQL主键用int还是varchar类型的一个小测试
- 用guid类型的字段作主键,用char(36)好还是用uniqueidentifier好?
- 数据库主键到底是用自增长(INT)好还是UUID好
- 使用Guid做主键和int做主键性能比较
- Guid做主键和int做主键性能比较
- 主键设置,总的来说int>Guid/string