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

2022-05-22 0 603

本文实例讲述了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相关内容感兴趣的读者可查看本站专题

免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。 不得使用于非法商业用途,不得违反国家法律。否则后果自负!

2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。

NICE源码网 MySql MySQL数据库列的增删改实现方法 https://www.niceym.com/49662.html