找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 66|回复: 0

alter table 更改表

[复制链接]

32

主题

0

回帖

164

积分

管理员

积分
164
发表于 2026-10-22 21:23:56 | 显示全部楼层 |阅读模式
alter table tb_name add [column] col_definition [first | after some_column];添加新字段

alter table tb_name add index [index_name] (index_col_name,...);
添加索引

alter table tb_name drop index index_name;
删除索引

alter table tb_name add primary key (index_col_name,...);
添加主键

alter table tb_name drop primary key;
删除主键

alter table tb_name add unique [index_name] (index_col_name,...);
添加唯一索引

alter table tb_name alter [column] col_name {set default default_value | drop default};
修改或删除字段默认值

alter table tb_name modify [column] create_definition;
修改字段定义

alter table tb_name change [column] old_col_name create_definition;
修改字段名、字段定义

alter table tb_name drop [column] col_name;
删除字段

alter table tb_name rename [as] new_tb_name;
修改表名

rename table tb_name1 to tb_name2;
修改表名
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|生活随笔 ( 豫ICP备2026037191号-1 )

GMT+8, 2026-11-10 09:58 , Processed in 0.046878 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表