开始创建表:
create table if not exists ta(
id smallint not null auto_increment,
title varchar not null
);系统会报错:you have a errno in your sql syntax; check the manual that corrresponds to your mysql server version for the right syntax to use near 'not null'.....
更改创建命令:
create table if not exists ta(
id smallint not null auto_increment,
title varchar(255) not null
);query Ok; 命令被正确执行
若更改varchar类型为char,同时不指定类型的最大值:
create table if not exists ta(
id smallint not null auto_increment,
title char not null
);query OK ;命令被正确执行小结:在给列设置string类型的时候,如果指定列的类型为varchar则需要指定该类型的最大‘容量值‘,若为char类型则不必。
本文详细解析了SQL中使用varchar类型时需要指定最大容量的原因,并通过实例展示了如何正确设置列类型以避免语法错误。同时,还总结了在不同场景下选择char和varchar的建议。

被折叠的 条评论
为什么被折叠?



