您使用什么数据类型来存储ID?

时间:2022-10-18 00:04:07

Why is there a minimum character count for posting questions? o.O

为什么发布问题的最小字符数? o.O

Do you use int, bigint, tinyint, whatever?

你使用int,bigint,tinyint等等吗?

It seems like a small thing I guess, I was just wondering what the usual practice is

我想这似乎是一件小事,我只是想知道通常的做法是什么

7 个解决方案

#1


6  

It all depends ... my favorite answer to a question! =)

这一切都取决于......我最喜欢的问题答案! =)

Most of the time we use Guids. While they are larger, size-wise, than int, tinyint and so on, I like the fact that my business objects can know what the value is before inserting records into the database.

大多数时候我们使用Guids。虽然它们比int,tinyint等更大,尺寸更大,但我喜欢这样的事实:在将记录插入数据库之前,我的业务对象可以知道值是什么。

At other times I may use strings, for things like customer id, where it might need to be easily recognized when working with the database.

在其他时候,我可能会使用字符串,例如客户ID,在使用数据库时可能需要轻松识别。

#2


1  

I've found int to be plenty large.

我发现int足够大了。

Going smaller is pointless . . .

变小是毫无意义的。 。 。

#3


1  

We use GUIDs as well.

我们也使用GUID。

It works better to synchronize multiple foreign database into one data warehouse. The drawback is it isn't as easy to figure out which items were created first, but you can still store the creation date or an autonomber if that is truly a problem.

它可以更好地将多个外部数据库同步到一个数据仓库中。缺点是要弄清楚首先创建了哪些项目并不容易,但如果确实存在问题,您仍然可以存储创建日期或自动生成器。

#4


1  

I like Guid's very much. The best thing is they can easily be generated on client or server without making any trips to the database. Also if you have to synchronise databases ever they will be a god send. The only disadvantage I find is with web apps if you pass the key on the url then you can easily get messy query strings.

我非常喜欢Guid。最好的是它们可以很容易地在客户端或服务器上生成,而无需访问数据库。此外,如果你必须同步数据库,他们将成为神派。我找到的唯一缺点是使用网络应用程序,如果你传递了网址上的密钥,那么你很容易得到凌乱的查询字符串。

#5


0  

Wouldn't it depend on how many ids you're likely to need to store over the lifetime of the app?

这取决于您在应用程序的生命周期内可能需要存储多少个ID?

#6


0  

Need more information. What kind of IDs are you storing? Anything smaller than int is probably a bad idea, a string might make sense given that it doesn't have the tiny issue of running out of digits, and isn't constrained constrained by numbers, so you could use a username as an id, for example.

需要更多信息。你要存储什么样的ID?任何小于int的东西都可能是一个坏主意,一个字符串可能有意义,因为它没有数字用尽的小问题,并且不受数字约束,因此你可以使用用户名作为id,例如。

#7


0  

I'll echo Jason with regards to always having a comparative column when using guids. I prefer sequences over guids though as you'll want a sequence either way.

关于在使用guid时总是有比较专栏,我会回应Jason。我更喜欢序列而不是guid,因为你会想要一个序列。

Datatype-wise, it depends on how many records you need to store, but int usually suffices.

数据类型,它取决于您需要存储多少条记录,但int通常就足够了。

#1


6  

It all depends ... my favorite answer to a question! =)

这一切都取决于......我最喜欢的问题答案! =)

Most of the time we use Guids. While they are larger, size-wise, than int, tinyint and so on, I like the fact that my business objects can know what the value is before inserting records into the database.

大多数时候我们使用Guids。虽然它们比int,tinyint等更大,尺寸更大,但我喜欢这样的事实:在将记录插入数据库之前,我的业务对象可以知道值是什么。

At other times I may use strings, for things like customer id, where it might need to be easily recognized when working with the database.

在其他时候,我可能会使用字符串,例如客户ID,在使用数据库时可能需要轻松识别。

#2


1  

I've found int to be plenty large.

我发现int足够大了。

Going smaller is pointless . . .

变小是毫无意义的。 。 。

#3


1  

We use GUIDs as well.

我们也使用GUID。

It works better to synchronize multiple foreign database into one data warehouse. The drawback is it isn't as easy to figure out which items were created first, but you can still store the creation date or an autonomber if that is truly a problem.

它可以更好地将多个外部数据库同步到一个数据仓库中。缺点是要弄清楚首先创建了哪些项目并不容易,但如果确实存在问题,您仍然可以存储创建日期或自动生成器。

#4


1  

I like Guid's very much. The best thing is they can easily be generated on client or server without making any trips to the database. Also if you have to synchronise databases ever they will be a god send. The only disadvantage I find is with web apps if you pass the key on the url then you can easily get messy query strings.

我非常喜欢Guid。最好的是它们可以很容易地在客户端或服务器上生成,而无需访问数据库。此外,如果你必须同步数据库,他们将成为神派。我找到的唯一缺点是使用网络应用程序,如果你传递了网址上的密钥,那么你很容易得到凌乱的查询字符串。

#5


0  

Wouldn't it depend on how many ids you're likely to need to store over the lifetime of the app?

这取决于您在应用程序的生命周期内可能需要存储多少个ID?

#6


0  

Need more information. What kind of IDs are you storing? Anything smaller than int is probably a bad idea, a string might make sense given that it doesn't have the tiny issue of running out of digits, and isn't constrained constrained by numbers, so you could use a username as an id, for example.

需要更多信息。你要存储什么样的ID?任何小于int的东西都可能是一个坏主意,一个字符串可能有意义,因为它没有数字用尽的小问题,并且不受数字约束,因此你可以使用用户名作为id,例如。

#7


0  

I'll echo Jason with regards to always having a comparative column when using guids. I prefer sequences over guids though as you'll want a sequence either way.

关于在使用guid时总是有比较专栏,我会回应Jason。我更喜欢序列而不是guid,因为你会想要一个序列。

Datatype-wise, it depends on how many records you need to store, but int usually suffices.

数据类型,它取决于您需要存储多少条记录,但int通常就足够了。