Int id与varchar id [英] Int id vs. varchar id
本文介绍了Int id与varchar id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪种类型的id更适合在mysql中查询和用作外键:
Which type of id is better for querying and to use as foreign key in mysql:
1)大小为20的varchar id
1)Varchar id with size 20
2)Int id
推荐答案
int通常更好,因为它可以提供更好的性能。
An int is usually better, because it gives better performance.
如果您的商品有自然键,是一个varchar,你可以使用它,它会工作。但是,通过添加代理键,您将获得性能提升(以及其他一些好处)整数。您可以为此添加 AUTO_INCREMENT
列。
If your item has a natural key which is a varchar, you could use that and it will work. But you will get a performance improvement (and some other benefits) by adding a surrogate key that is an integer. You can add an AUTO_INCREMENT
column for this purpose.
这篇关于Int id与varchar id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文