简体   繁体   中英

MySQL - How do I use CONCAT in ALTER TABLE?

How do I concatenate in 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.

You're misusing 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:

  • INSERT
  • UPDATE
  • DELETE

Use update after you add a column to fill it out:

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 . Computed columns would solve this, but I don't think they're available on MySQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM