MySQL Mysql中uniqueidentifier的替代品是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8180019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:45:03  来源:igfitidea点击:

What is the replacement for uniqueidentifier in Mysql

mysqlsql-serveruniqueidentifier

提问by jimmy

I have a query from SQL Server which I want to run in Mysql. but I cannot find any replacement for uniqueidentifierkeyword from SQL Server script to MYSQL Script.

我有一个来自 SQL Server 的查询,我想在 Mysql 中运行它。但我找不到uniqueidentifier从 SQL Server 脚本到 MYSQL 脚本的关键字的任何替代品。

Here is the query

这是查询

 CREATE TABLE foo(
  myid uniqueidentifier NOT NULL,
  barid uniqueidentifier NOT NULL
)

What will be the query in Mysql for the same above SQL Server script?

对于上述 SQL Server 脚本,Mysql 中的查询将是什么?

回答by Joe Harris

The accepted answer, although not exactly wrong, is somewhat incomplete. There certainly are more space efficient ways to store GUID/UUIDs. Please have a look at this question: "Storing MySQL GUID/UUIDs"

接受的答案虽然不完全错误,但有些不完整。当然有更节省空间的方法来存储 GUID/UUID。请看看这个问题:“存储 MySQL GUID/UUID”

This is the best way I could come up with to convert a MySQL GUID/UUID generated by UUID() to a binary(16):

UNHEX(REPLACE(UUID(),'-',''))

And then storing it in a BINARY(16)

这是将 UUID() 生成的 MySQL GUID/UUID 转换为二进制文件 (16) 的最佳方法:

UNHEX(REPLACE(UUID(),'-',''))

然后将其存储在 BINARY(16) 中

If storage space of the GUID/UUID is a primary concern this method will deliver significant savings.

如果 GUID/UUID 的存储空间是主要问题,则此方法将节省大量资金。

回答by N.B.

CREATE TABLE FOO (
myid CHAR(38) NOT NULL,
barid CHAR(38) NOT NULL
);

According to MS website, GUID's are 38 chars in length.

根据 MS 网站,GUID 的长度为 38 个字符。

回答by Doolali

According the the MySQL website you should match it to VARCHAR(64)

根据 MySQL 网站,您应该将其与 VARCHAR(64) 匹配

UNIQUEIDENTIFIER,   VARCHAR(64)

http://dev.mysql.com/doc/workbench/en/wb-migration-database-mssql-typemapping.html

http://dev.mysql.com/doc/workbench/en/wb-migration-database-mssql-typemapping.html

回答by Oliver

Remember also that a 16 byte value is represented in hex as 32 bytes. With the 4 dashes and the 2 curly braces, that gets us the 38 bytes in this format compatible with SQL Server with a 38 byte string. For example: {2DCBF868-56D7-4BED-B0F8-84555B4AD691}.

还要记住,16 字节的值以十六进制表示为 32 字节。使用 4 个破折号和 2 个花括号,我们得到了这种格式的 38 个字节,与具有 38 个字节字符串的 SQL Server 兼容。例如:{2DCBF868-56D7-4BED-B0F8-84555B4AD691}。