MySql数据库之alter表的SQL语句集合
程序员文章站
2024-02-22 20:01:52
mysql之alter表的sql语句集合,包括增加、修改、删除字段,重命名表,添加、删除主键等。
1:删除列
alter table 【表名字】 drop 【列名称】...
mysql之alter表的sql语句集合,包括增加、修改、删除字段,重命名表,添加、删除主键等。
1:删除列
alter table 【表名字】 drop 【列名称】
2:增加列
alter table 【表名字】 add 【列名称】 int not null comment '注释说明'
3:修改列的类型信息
alter table 【表名字】 change 【列名称】【新列名称(这里可以用和原来列同名即可)】 bigint not null comment '注释说明'
4:重命名列
alter table 【表名字】 change 【列名称】【新列名称】 bigint not null comment '注释说明'
5:重命名表
alter table 【表名字】 rename 【表新名字】
6:删除表中主键
alter table 【表名字】 drop primary key
7:添加主键
alter table sj_resource_charges add constraint pk_sj_resource_charges primary key (resid,resfromid)
8:添加索引
alter table sj_resource_charges add index index_name (name);
9: 添加唯一限制条件索引
alter table sj_resource_charges add unique emp_name2(cardnumber);
10: 删除索引
alter table tablename drop index emp_name;
以上内容是小编给大家介绍的mysql数据库之alter表的sql语句集合,希望对大家有所帮助!
上一篇: MySQL分页优化
下一篇: 编写简易Android天气应用的代码示例