
MySQL使用alter修改表的结构
发布日期:2021-05-07 16:40:07
浏览次数:30
分类:原创文章
本文共 1882 字,大约阅读时间需要 6 分钟。
SQL语句
DLL 数据定义语言
create,drop
DML 数据操纵语言
insert,delete,select,update
DCL 数据控制语言
grant,revoke
使用ALTER TABLE修改表结构
(1)修改表名
ALTER TABLE <表名> RENAME <新表名>
mysql> alter table game_account rename account;Query OK, 0 rows affected (0.05 sec)
(2)修改表的搜索引擎
mysql> alter table account engine=MyISAM;Query OK, 0 rows affected (0.05 sec)Records: 0 Duplicates: 0 Warnings: 0
查看表的信息
mysql> show create table account\G;*************************** 1. row *************************** Table: accountCreate Table: CREATE TABLE `account` ( `game_name` char(15) NOT NULL, `game_password` char(25) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin11 row in set (0.00 sec)ERROR: No query specified
(3)添加字段
ALTER TABLE <表名> ADD <字段名称> <字段定义>
后面添加:
mysql> alter table account add game_sex enum("M","F") not null;
前面添加:
mysql> alter table account add game_address varchar(20) not null default "huabei" first;Query OK, 0 rows affected (0.00 sec)Records: 0 Duplicates: 0 Warnings: 0
中间添加:
mysql> alter table account add game_money int after game_name;Query OK, 0 rows affected (0.00 sec)Records: 0 Duplicates: 0 Warnings: 0
(4)删除字段
ALTER TABLE <表名> drop <字段名称>
mysql> alter table account drop game_wei;Query OK, 0 rows affected (0.00 sec)Records: 0 Duplicates: 0 Warnings: 0
(5)修改字段名称及字段定义
ALTER TABLE <表名> CHANGE <旧字段> <新字段名称> <字段定义>
mysql> alter table account change game_zhang wei char(25) not null;Query OK, 0 rows affected (0.01 sec)Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table account change wei wei varchar(60) ;Query OK, 0 rows affected (0.00 sec)Records: 0 Duplicates: 0 Warnings: 0
(6)修改字段定义
ALTER TABLE <表名> MODIFY <字段名称> <字段定义>
mysql> alter table account modify wei int ;Query OK, 0 rows affected (0.01 sec)Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table account modify wei int not null ;Query OK, 0 rows affected (0.01 sec)Records: 0 Duplicates: 0 Warnings: 0
发表评论
最新留言
感谢大佬
[***.8.128.20]2025年03月25日 23时50分01秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
大规模集群自动化部署工具--Chef的安装部署
2019-03-05
自定义Hive Sql Job分析工具
2019-03-05
【MySQL】(九)触发器
2019-03-05
关于Altium Designer 09导出BOM表不能正确分类问题
2019-03-05
Oracle 11G环境配置
2019-03-05
【Python】(十二)IO 文件处理
2019-03-05
【Oozie】(三)Oozie 使用实战教学,带你快速上手!
2019-03-05
师兄面试遇到这条 SQL 数据分析题,差点含泪而归!
2019-03-05
C语言的数值溢出问题(上)
2019-03-05
BottomNavigationView控件item多于3个时文字不显示
2019-03-05
函数指针的典型应用-计算函数的定积分(矩形法思想)
2019-03-05
8051单片机(STC89C52)以定时器中断模式实现两倒计时器异步计时
2019-03-05
用 wxPython 打印你的 App
2019-03-05
vue项目通过vue.config.js配置文件进行proxy反向代理跨域
2019-03-05
Linux下安装MySql过程
2019-03-05
android:使用audiotrack 类播放wav文件
2019-03-05
vue通过better-scroll 封装自定义的下拉刷新组件
2019-03-05
android解决:使用多线程和Handler同步更新UI
2019-03-05
vue自定义封装Loading组件
2019-03-05
Element UI 中动态路由的分析及实现
2019-03-05