讨教在表建好以后,想增加枚举类型,该怎么操作
解决方案
5
直接 :
alter table
add 列名 enum(….)
alter table
add 列名 enum(….)
15
直接加就行了:
mysql> create table tx(t enum(“1″,”2”));
Query OK, 0 rows affected (0.63 sec)
mysql> insert into tx values(“1”);
Query OK, 1 row affected (0.09 sec)
mysql> insert into tx values(“2”);
Query OK, 1 row affected (0.06 sec)
mysql> select * from tx;
+–+
| t |
+–+
| 1 |
| 2 |
+–+
2 rows in set (0.01 sec)
mysql> alter table tx
-> modify column t enum(“1″,”2″,”3”);
Query OK, 0 rows affected (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table tx;
+–+–+
| Table | Create Table |
+–+–+
| tx | CREATE TABLE `tx` (
`t` enum(“1″,”2″,”3”) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+–+–+
1 row in set (0.01 sec)
mysql> select * from tx;
+–+
| t |
+–+
| 1 |
| 2 |
+–+
2 rows in set (0.01 sec)
mysql> insert into tx values(“3”);
Query OK, 1 row affected (0.14 sec)
mysql> select * from tx;
+–+
| t |
+–+
| 1 |
| 2 |
| 3 |
+–+
3 rows in set (0.00 sec)
mysql>
mysql> create table tx(t enum(“1″,”2”));
Query OK, 0 rows affected (0.63 sec)
mysql> insert into tx values(“1”);
Query OK, 1 row affected (0.09 sec)
mysql> insert into tx values(“2”);
Query OK, 1 row affected (0.06 sec)
mysql> select * from tx;
+–+
| t |
+–+
| 1 |
| 2 |
+–+
2 rows in set (0.01 sec)
mysql> alter table tx
-> modify column t enum(“1″,”2″,”3”);
Query OK, 0 rows affected (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table tx;
+–+–+
| Table | Create Table |
+–+–+
| tx | CREATE TABLE `tx` (
`t` enum(“1″,”2″,”3”) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+–+–+
1 row in set (0.01 sec)
mysql> select * from tx;
+–+
| t |
+–+
| 1 |
| 2 |
+–+
2 rows in set (0.01 sec)
mysql> insert into tx values(“3”);
Query OK, 1 row affected (0.14 sec)
mysql> select * from tx;
+–+
| t |
+–+
| 1 |
| 2 |
| 3 |
+–+
3 rows in set (0.00 sec)
mysql>