Mysql建立计算列错误Expression of generated column ‘electricity‘ contains a disallowed function: rand.

MySQL的CREATETABLE语句中,生成列的表达式必须遵循特定规则,只允许使用确定性的内置函数和运算符,如常量和不依赖于连接用户的函数。文章指出RAND()函数因其非确定性,每次调用可能产生不同结果,因此在生成列中是被禁止的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决办法:
在这里插入图片描述

From MySQL documentation 13.1.18.7 CREATE TABLE and Generated Columns:

Generated column expressions must adhere to the following rules. An error occurs if an expression contains disallowed constructs.

Literals, deterministic built-in functions, and operators are permitted. A function is deterministic if, given the same data in tables, multiple invocations produce the same result, independently of the connected user. Examples of functions that are nondeterministic and fail this definition: CONNECTION_ID(), CURRENT_USER(), NOW().

翻译:
在这里插入图片描述
rand()函数每次会产生不同结果,所以是不允许的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值