gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 15:38:23 25 4
gpt4 key购买 nike

我想做这样的事情:


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



但是,这会导致错误,有没有办法在mysql中为默认值调用函数?

谢谢。

最佳答案

不,你不能。

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

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

关于mysql - 我可以在MySql中使用函数作为默认值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57969490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com