mysql uuid默认值问题

PitTroll 2012-01-11 10:49:11
刚接触mysql,现在我给表的ID列添加默认值时这样写:
ID BINARY(16) DEFAULT UNHEX(REPLACE(UUID(),'-','')) NOT NULL,
在导入的时候提示错误。
怎么给该ID列添加一个UUID类型的默认值呢?我的版本是5.5.19
...全文
1874 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2012-01-11
  • 打赏
  • 举报
回复

[Quote]10.1.4. Data Type Default Values
The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column. See Section 10.3.1.1, “TIMESTAMP Properties”.

[/Quote]
ACMAIN_CHM 2012-01-11
  • 打赏
  • 举报
回复
MYSQL无法在默认值中设置UUID函数,实际上其它函数除TIMESTAMP之外都不可以。 MYSQL的默认值目前只能是常数或者CURRENTTIMESTAMP。

如果需要实现UUID为默认值的功能,则可以在该表的INSERT触发器中实现。
PitTroll 2012-01-11
  • 打赏
  • 举报
回复
恩,找到了,mysql不支持函数作为默认值
rucypli 2012-01-11
  • 打赏
  • 举报
回复
无法默认uuid 建议默认int auto_increment primary key
WWWWA 2012-01-11
  • 打赏
  • 举报
回复
怎样建表、导入的?跳过此列能否导入?

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧