
GBase 8a数据库集群,目前不支持字段的定义修改,除了varchar类型可以增加长度,其它的类型或属性均不可以,需要重建一个字段过渡一下。
varchar类型增加长度
请一定保留原有的附加属性,包括not null, default 等。否则change时会报错。单独修改注释等,请用modify功能。
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>
其它类型变动
其它类型只有先建一个新的字段,然后把数据update过去,然后把老的删除,把新的change成老的字段名。
如下例子,把value bigint, 改成 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)
本文的功能经常用到,虽然系统可以修改字段类型,但还是建议在设计阶段控制好,特别是避免从高精度,高长度更改为低精度,低长度的情况。 特别是varchar并不是实际占用空间。
gbase是一种数据库系统,可以在其中导入Windows文件,其具体步骤如下:1. 打开gbase,登录数据库系统。
2. 创建一个表来存储Windows文件的数据,例如文件名、文件路径、文件大小等。
3. 通过SQL语句将Windows文件的数据插入到该表中。可以使用INSERT语句将数据逐行插入,也可以使用LOAD DATA INFILE语句进行批量插入。
4. 在插入数据时,需要指定Windows文件的路径,可以使用Windows文件资源管理器中的复制路径功能来获取文件的路径,然后在SQL语句中使用该路径。
5. 对于大文件,建议使用BLOB类型来存储文件数据,可以使用BINARY()函数将文件内容转换为二进制格式,然后插入到BLOB类型的字段中。
6. 在插入完成后,可以使用SELECT语句查询该表中的数据,验证导入是否成功。
注意事项:
1. 在插入数据时,需要考虑文件大小、文件类型、文件编码等因素,以避免出现数据丢失或格式不正确的情况。
2. 对于敏感数据,需要进行加密保护,以保证数据安全性。
3. 在使用LOAD DATA INFILE语句进行批量导入时,要特别注意文件路径和文件格式等参数的设置,以确保数据导入成功。
可以添加。首先使用gbasedbt用户创建一个chunk
touch datachunk1
chmod 660 datachunk1
然后向数据库增加chunk
onspaces -c -d datadbs -p /opt/ gbase8s/dbs/datachunk1 -o 0 -s 51200
说明:-c 创建dbspace
-d 创建的dbspace 名称
-p 创建dbspace的chunk磁盘分区
-o 磁盘分区的偏移量
-s dbspace 初始chunk的大小,单位为kb
最后可以创建数据库
create database testdb1 in datadbs with log
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)