-3

I am designing a database with a table to store vehicles and since the vehicle identification number is a 17 digit alphanumeric serial number my idea is to use it as the primary key, with a datatype of char(17).

Numerous other tables will then have the VIN as a foreign key.

A number of queries/searches will run with the VIN number as parameter since it's how we would like to track the vehicles as well as other data related to it.

The VIN number will never change, but I'm unsure if it would cause any serious performance degradation (or other complications I'm not aware of) since some queries will use joins and others not :/

By using the VIN as primary key I do not have to create a unique constraint / additional index - BUT it has to be char(17) a data type other than int for which primary keys are supposedly optimized...

What I'm also not 200% sure of is that every VIN number out there is the same length (very unlikely) but in that case how would using a varchar(17) affect the whole situation... if at all.

Thanks!

4

2 回答 2

0

纯属个人意见。。

我总是使用 int 作为主键。主键在大多数情况下始终是聚集索引。它是 4 个字节与 17 个字节,您始终可以在您的 VIN 列上放置一个非聚集索引。保持简单明了。这只是我的意见。

于 2015-01-20T10:48:10.493 回答
0

在我看来,关于性能,这确实不是一个好主意。不过,这在很大程度上取决于您将在数据库中存储多少辆汽车。另一方面,如果您的应用程序和查询使用 VIN 作为参数,那么它是最佳选择,因为该列已编入索引并且必须是唯一的。

希望这可以帮助

ps:看到别人对这个话题的建议真是不好意思!

于 2015-01-20T10:44:09.563 回答