如何在MySQL中将一列默认值分配给另一列的值? [英] How do you assign a column default in MySQL to another column's value?

查看:179
本文介绍了如何在MySQL中将一列默认值分配给另一列的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MySQL数据库的表中添加新列,该表应获取同一表中另一列的值.这可能吗?如果是这样,您该怎么做?

I want to add a new column to a table in MySQL database that should get the value of another column in the same table. Is this possible? If so, how do you do it?

推荐答案

从MySQL 5.0.2开始,您可以编写链接到

Starting with MySQL 5.0.2 you can write a stored procedure linked to a TRIGGER which can examine the new column each time a row is inserted, and automatically copy the other column's value into the new column if no value was supplied for the new column.

这篇关于如何在MySQL中将一列默认值分配给另一列的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆