guid作为主键? [英] guid as primary key?

查看:252
本文介绍了guid作为主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mysql数据库,其中有3个表必须结合在一起.我收到了一些较小的数据库,这些数据库必须提供此mysql数据库,并在获得新数据时附加它们.我遇到的问题是,我得到的较小的数据库是由外部应用程序生成的,并不是真正要一起使用.因此,当我使用较小数据库的架构时,我无法知道它们来自3个表的所有记录如何一起构成的.

I have a mysql database which has 3 tables that have to be joined together. I receive smaller databases that must feed this mysql database, appending the new data as I get it. The problem I have is the smaller dbs that I get are generated by an outside application and are not really meant to be used all together. Therefore, when I utilize the schema of the smaller database, I have no way to know how they all the records from the 3 tables belong together.

我正在考虑插入一个GUID作为主键,可以将其添加到表中,并在插入所有新数据时插入.
但是,我很乐意使用char字段(用于存储GUID)作为键.这是一个有效的问题,还是使用char字段知道它将永远是一个向导是一个足够的解决方案?有人可以推荐一种更好的方法吗?

I was thinking about inserting a guid to serve as a primary key that I can add to the tables and insert when I insert all of the new data.
However, I am leery of using a char field (used to store the guid) as a key. Is this a valid concern, or is using char field knowing that it will always be a guid a sufficient solution? Can someone recommend a better approach?

谢谢

推荐答案

MySQL不提供GUID/UUID类型,因此您需要在用于向数据库中插入行的代码中生成密钥. char(32)char(36)(如果包含连字符)是代替实际GUID数据类型存储GUID的最佳数据类型.

MySQL does not provide a GUID/UUID type, so you would need to generate the key in the code you're using to insert rows into the DB. A char(32) or char(36) (if including hyphens) is the best data type to store a GUID in lieu of an actual GUID data type.

这篇关于guid作为主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆