最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]MySQL中插入新的列

MySQL crifan 2425浏览 0评论

对于:

MariaDB [guanzhi_removeDuplicate]> SHOW COLUMNS from selection;
+————+————-+——+—–+———+—————-+
| Field      | Type        | Null | Key | Default | Extra          |
+————+————-+——+—–+———+—————-+
| id         | int(10)     | NO   | PRI | NULL    | auto_increment |
| staff_id   | int(10)     | NO   | MUL | NULL    |                |
| car_sn     | varchar(10) | NO   |     | NULL    |                |
| bid_price  | int(10)     | NO   |     | NULL    |                |
| created_at | int(10)     | NO   |     | NULL    |                |
| sequence   | int(10)     | NO   |     | NULL    |                |
+————+————-+——+—–+———+—————-+
6 rows in set (0.00 sec)

 

想要新增列

created_at_gmt8

mysql insert new column

SQL ALTER TABLE Statement

php – How to add new column to MYSQL table – Stack Overflow

Add a column to an existing MySQL table

SQL – ADD COLUMN | 1Keydata

MySQL: ALTER TABLE Statement

好像是:

MariaDB [guanzhi_removeDuplicate]> ALTER TABLE selection ADD created_at_gmt8 int(10) after created_at;
Query OK, 2273 rows affected (1.33 sec)                
Records: 2273  Duplicates: 0  Warnings: 0
MariaDB [guanzhi_removeDuplicate]> SHOW COLUMNS from selection;
+—————–+————-+——+—–+———+—————-+
| Field           | Type        | Null | Key | Default | Extra          |
+—————–+————-+——+—–+———+—————-+
| id              | int(10)     | NO   | PRI | NULL    | auto_increment |
| staff_id        | int(10)     | NO   | MUL | NULL    |                |
| car_sn          | varchar(10) | NO   |     | NULL    |                |
| bid_price       | int(10)     | NO   |     | NULL    |                |
| created_at      | int(10)     | NO   |     | NULL    |                |
| created_at_gmt8 | int(10)     | YES  |     | NULL    |                |
| sequence        | int(10)     | NO   |     | NULL    |                |
+—————–+————-+——+—–+———+—————-+
7 rows in set (0.00 sec)
MariaDB [guanzhi_removeDuplicate]>

应该加上not null的:

ALTER TABLE selection ADD created_at_gmt8 int(10) after created_at NOT NULL;

但是已经加过了,没法再加了。

所以要去修改已有的列:

[已解决]mysql修改已有列的属性

转载请注明:在路上 » [已解决]MySQL中插入新的列

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.181 seconds, using 22.18MB memory