暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

OceanBase 4.0 社区版和OceanBase 3.2 企业版将默认空字段修改为非空的差异

原创 尚雷 2022-12-29
1728

– 本次主要对比OceanBase 对MySQL的语法兼容性,因OceanBase 社区版 4.0 不提供Oracle 多租户。

一、OceanBase 4.0 社区版

[admin@obproxy-node ~]$ obclient -h 10.110.3.xxx -uroot@sys#obcluster -pxxx -P2883 -c -A oceanbase
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 19
Server version: OceanBase_CE 4.0.0.0 (r100000282022112511-dd289d2407609a88b1fcdf2be9e7c384cb8e19d0) (Built Nov 25 2022 11:58:08)
 
Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
obclient [oceanbase]> use test;
Database changed
obclient [test]> CREATE TABLE ob4_tb1 (
    ->             id DECIMAL COMMENT '主键',
    ->             trade_no VARCHAR(64),
    ->             channel VARCHAR(2)
    ->             );
Query OK, 0 rows affected (0.095 sec)
 
obclient [test]> desc ob4_tb1;
+----------+---------------+------+-----+---------+-------+
| Field    | Type          | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| id       | decimal(10,0) | YES  |     | NULL    |       |
| trade_no | varchar(64)   | YES  |     | NULL    |       |
| channel  | varchar(2)    | YES  |     | NULL    |       |
+----------+---------------+------+-----+---------+-------+
3 rows in set (0.209 sec)
 
obclient [test]> ALTER TABLE ob4_tb1 MODIFY id DECIMAL(40,2) NOT NULL;
Query OK, 0 rows affected (0.741 sec)
 
obclient [test]> desc ob4_tb1;
+----------+---------------+------+-----+---------+-------+
| Field    | Type          | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| id       | decimal(40,2) | NO   |     | NULL    |       |
| trade_no | varchar(64)   | YES  |     | NULL    |       |
| channel  | varchar(2)    | YES  |     | NULL    |       |
+----------+---------------+------+-----+---------+-------+
3 rows in set (0.014 sec)

一、OceanBase 3.0 企业版

[admin@ob1 ~]$ mysql -h10.110.7.xx -P2883 -uroot@sxxx -pbbBB22__
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1776981
Server version: 5.6.25 OceanBase 3.2.4.0 (r100000072022102819-2a28da9e758e2d232c41fa1a1b0070a08b77dd7d) (Built Oct 28 2022 19:46:38)
 
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
MySQL [(none)]> use test;
Database changed
MySQL [test]> CREATE TABLE ob3_tb1 (
    ->             id DECIMAL COMMENT '主键',
    ->             trade_no VARCHAR(64),
    ->             channel VARCHAR(2)
    ->             );
Query OK, 0 rows affected (0.04 sec)
 
MySQL [test]> desc ob3_tb1;
+----------+---------------+------+-----+---------+-------+
| Field    | Type          | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| id       | decimal(10,0) | YES  |     | NULL    |       |
| trade_no | varchar(64)   | YES  |     | NULL    |       |
| channel  | varchar(2)    | YES  |     | NULL    |       |
+----------+---------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
 
MySQL [test]> ALTER TABLE ob3_tb1 MODIFY id DECIMAL(40,2) NOT NULL;
ERROR 1138 (22004): Invalid use of NULL value
 
 
MySQL [test]> CREATE TABLE ob3_tb2 (
    ->             id DECIMAL not null COMMENT '主键',
    ->             trade_no VARCHAR(64) not null,
    ->             channel VARCHAR(2) not null
    ->             );
Query OK, 0 rows affected (0.17 sec)
 
MySQL [test]> desc ob3_tb2;
+----------+---------------+------+-----+---------+-------+
| Field    | Type          | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+-------+
| id       | decimal(10,0) | NO   |     | NULL    |       |
| trade_no | varchar(64)   | NO   |     | NULL    |       |
| channel  | varchar(2)    | NO   |     | NULL    |       |
+----------+---------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

三、结论

在OceanBase 4.0 社区版和企业版 3.2上创建含有空字段的表,当对含有空字段的表设置非空时,4.0版本是允许修改的,而企业版是3.2 是不允许对默认为空的表字段设置为非空,只允许在建表时就指定表字段为非空。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论