MySQL数据库列的增删改实现方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

MySQL数据库列的增删改实现方法

小菜鸟有大梦想   2020-12-15 我要评论
这篇文章主要介绍了MySQL数据库列的增删改实现方法,结合实例形式分析了mysql数据库针对列的增加、修改、删除等相关操作sql命令及使用技巧,需要的朋友可以参考下

本文实例讲述了MySQL数据库列的增删改实现方法。分享给大家供大家参考,具体如下:

新建表user_info:

CREATE TABLE user_info(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
username CHAR(20) NOT NULL DEFAULT '',
gender TINYINT UNSIGNED NOT NULL DEFAULT 0,
weight TINYINT UNSIGNED NOT NULL DEFAULT 0
)ENGINE=MyISAM DEFAULT CHARSET=utf8;

新增列默认在表的最后一列

语法:alter table 表名 add 列名 列类型 列属性

alter table user_info add height tinyint unsigned not null default 0;

删除列

语法:alter table 表名 drop 列名

alter table user_info drop height;

增加列,放在指定列之后

语法:alter table 表名 add 列名 类型 属性 [默认值] after 指定列名

alter table user_info add height tinyint not null default 0 after username;

修改指定列名

语法:alter table 表名 change 旧列名 新列名 类型 属性 默认值

alter table user_info change height shengao smallint not null default 0;

modify 修改列,但不能修改列名

语法:alter table 表名 modify 列名 类型 属性 默认值

alter table user_info modify shengao tinyint not null default 0;

希望本文所述对大家MySQL数据库计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们