GBase 8a aumenta la longitud del campo o cambia la definición del tipo

El clúster de base de datos de GBase 8a actualmente no admite la modificación de la definición del campo. Excepto para el tipo varchar, la longitud se puede aumentar, no se permiten otros tipos o atributos. Es necesario reconstruir un campo para la transición.

Consulte  http://www.gbase8.cn/1357

El tipo varchar aumenta la longitud

Asegúrese de mantener los atributos adicionales originales, incluidos no nulo, predeterminado, etc. De lo contrario, se informará de un error al cambiar. Para modificar los comentarios individualmente, utilice la función de modificación.

gbase> desc t2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (Elapsed: 00:00:00.00)

gbase> alter table t2 change name  name varchar(30);
Query OK, 0 rows affected, 1 warning (Elapsed: 00:00:00.98)
Records: 0  Duplicates: 0  Warnings: 0

gbase> desc t2;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
| name  | varchar(30) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (Elapsed: 00:00:00.00)

gbase> 

Otros tipos de cambios

Otros tipos solo tienen que crear un nuevo campo primero, luego actualizar los datos, luego eliminar el anterior y cambiar el nuevo por el nombre del campo anterior.

En el siguiente ejemplo, cambie value bigint por value int.

 

gbase> desc t1;
+-------+------------+------+-----+---------+-------+
| Field | Type       | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| id    | int(11)    | YES  | MUL | NULL    |       |
| value | bigint(20) | YES  |     | NULL    |       |
| birth | datetime   | YES  |     | NULL    |       |
+-------+------------+------+-----+---------+-------+
3 rows in set (Elapsed: 00:00:00.00)

gbase> alter table t1 add column value2 int after value;
Query OK, 4 rows affected (Elapsed: 00:00:00.65)
Records: 4  Duplicates: 4  Warnings: 0

gbase> desc t1;
+--------+------------+------+-----+---------+-------+
| Field  | Type       | Null | Key | Default | Extra |
+--------+------------+------+-----+---------+-------+
| id     | int(11)    | YES  | MUL | NULL    |       |
| value  | bigint(20) | YES  |     | NULL    |       |
| value2 | int(11)    | YES  |     | NULL    |       |
| birth  | datetime   | YES  |     | NULL    |       |
+--------+------------+------+-----+---------+-------+
4 rows in set (Elapsed: 00:00:00.00)

gbase> update t1 set value2=value;
Query OK, 4 rows affected (Elapsed: 00:00:00.28)
Rows matched: 4  Changed: 4  Warnings: 0

gbase> alter table t1 drop value;
Query OK, 4 rows affected (Elapsed: 00:00:00.42)
Records: 4  Duplicates: 4  Warnings: 0

gbase> desc t1;
+--------+----------+------+-----+---------+-------+
| Field  | Type     | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| id     | int(11)  | YES  | MUL | NULL    |       |
| value2 | int(11)  | YES  |     | NULL    |       |
| birth  | datetime | YES  |     | NULL    |       |
+--------+----------+------+-----+---------+-------+
3 rows in set (Elapsed: 00:00:00.00)

gbase> alter table t1 change value2 value int;
Query OK, 0 rows affected (Elapsed: 00:00:00.21)
Records: 0  Duplicates: 0  Warnings: 0

gbase> desc t1;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id    | int(11)  | YES  | MUL | NULL    |       |
| value | int(11)  | YES  |     | NULL    |       |
| birth | datetime | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
3 rows in set (Elapsed: 00:00:00.01)

Supongo que te gusta

Origin blog.csdn.net/java2000_net/article/details/108641452
Recomendado
Clasificación