[英]MySQL - How do I use CONCAT in ALTER TABLE?
How do I concatenate in ALTER TABLE
?如何在
ALTER TABLE
中连接?
I tried this, but it didn't work:我试过这个,但没有奏效:
$sql1="ALTER TABLE t1 ADD iod = CONCAT('10.1234','/',id)";
id
is a different column in the same table. id
是同一个表中的不同列。
You're misusing ALTER TABLE
.您在滥用
ALTER TABLE
。 It is intended to modify the data definition (structure) of a table, not its values.它旨在修改表的数据定义(结构),而不是其值。
If you want to modify the values in a table, you should use one of the following types of queries:如果要修改表中的值,应使用以下类型的查询之一:
Use update
after you add a column to fill it out:添加一列后使用
update
来填写它:
ALTER TABLE t1 ADD iod varchar(150)
UPDATE t1 SET iod = CONCAT('10.1234','/',id)
Any new rows that you add would have to include the proper value of iod
.您添加的任何新行都必须包含
iod
的正确值。 Computed columns would solve this, but I don't think they're available on MySQL.计算列可以解决这个问题,但我认为它们在 MySQL 上不可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.