Lightdb22.4兼容mysql alter modify修改表字段类型、默认值、非空约束

前言

继22.3版本兼容oracle alter table modify语法后,最近又接入mysql的应用,功能不足以应对现在的使用场景。要对mysql的alter table modify常用功能进行兼容。
oracle和mysql针对这个功能,区别在于:默认值(default)和非空约束(NOT NULL和NULL)位置可以交换;相同点:如果需要设置数据类型,则必须在默认值和非空约束前。

测试

新增测试用例如下(因为之前22.3兼容mysql alter modify修改表字段类型、默认值、非空约束已经涉及到大量的测试用例):

--默认值非空约束属性交换位置
create table test_modify(key1 int, key2 int);
alter table test_modify modify key1 varchar(100) not null default 'thanks';
insert into test_modify(key2) values (33);
select * from test_modify;drop table test_modify;

create table test_modify(key1 int,key2 int);
alter table test_modify modify key1 char not null;
alter table test_modify modify key1 not null; -- oracle fail
alter table test_modify modify key1 null;
alter table test_modify modify key1 default 'thanks'; --oracle fail
insert into test_modify(key2) values (33); -- fail when excute
alter table test_modify modify key1 varchar(100);
alter table test_modify modify key1 default 'thanks';
alter table test_modify modify key1 not null;
insert into test_modify(key2) values (33);
select * from test_modify;
drop table test_modify;

-- oracle default NULL, oracle is fail,but not lightdb and mysql
create table test_modify(key1 int,key2 int);
alter table test_modify modify key1 char null;
insert into test_modify(key2) values (33);
select * from test_modify;
drop table test_modify;

-- NOT NULL
create table test_modify(key1 int,key2 int);
alter table test_modify modify key1 char not null;
insert into test_modify(key2) values (33);
select * from test_modify;
drop table test_modify;

-- Abnormal
create table test_modify(key1 int,key2 int);
alter table test_modify modify key1 sfs char vvxvsv not null fgd default 'a'; --faild
rop table test_modify;

结论

(1)由于oracle默认属性是not null,因此不可以重复设置该属性;lightdb未作该限制。功能不影响。
(2)设置属性不合理,oracle会在修改默认属性对该类型长度进行判断;
lightdb不会立即报错,但是在执行插入的时候会报长度错误。功能不影响。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值