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 c开发者_JAVA技巧olumn 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.
精彩评论