MySQL查询以及修改表、表字段备注信息

您所在的位置:网站首页 mysql查询密码长度语句 MySQL查询以及修改表、表字段备注信息

MySQL查询以及修改表、表字段备注信息

2023-12-15 12:57| 来源: 网络整理| 查看: 265

在开发中,我们可能经常碰到这种问题,随着需求的变更,或者设计阶段的失误,表字段的长度太小,字段的备注信息需要完善。所以,就要更改表结构或者其它一些信息了。

话不多说,步入正题。

创建测试表:

create table student( id int(11) primary key, name varchar(50) comment '姓名', age int(4) comment '年龄', address varchar(50) comment '住址' ); 修改表备注信息:

alter table student comment '学生信息'; 修改表字段长度:

alter table student modify column address varchar(100);

这里需要注意的是:一般都是把字段长度调的更大,若是调小可能会影响现有数据。

修改表字段备注信息:

alter table student modify column address varchar(50) comment '家庭住址';

给表增加新的字段:

alter table student add sex varchar(2) comment '性别';

在指定的列后面增加新的列

alter table student add address varchar(200) comment '家庭住址' after sex;

删除表字段:

alter table student drop column sex;

查看表的备注:

use information_schema;information_schema是mysql数据库中的系统库,里面存放了,用户所创建的数据库和表的信息

select * from tables where table_schema = 'linxiaomi'(db name) and table_name = 'student';

查看表字段的备注:

use linxiaomi(db name); show full columns from student(table name);



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3