开发者社区 问答 正文

我可以在MySql中使用函数作为默认值吗?

我想做这样的事情:

create table app_users ( app_user_id smallint(6) not null auto_increment primary key, api_key char(36) not null default uuid() );

但是,这会导致错误,是否可以在mysql中为默认值调用函数?

谢谢。

展开
收起
保持可爱mmm 2020-05-11 16:41:03 691 分享 版权
1 条回答
写回答
取消 提交回答
  • 不,你不能。

    但是,您可以轻松创建触发器来执行此操作,例如:

    创建触发器before_insert_app_users 在app_users上插入之前 每行 SET new.api_key = uuid(); 来源:stack overflow

    2020-05-11 16:41:12
    赞同 展开评论