Mysql下修改表(alter)

1.修改表名
用法:
alter table 旧表名 rename 新表名;

alter table student rename students;
  1. 增加字段
    用法:
    alter table 表名 字段名 数据类型[完整性约束条件];
alter table teacher add sge tinyint;

3.删除字段
用法:
alter table 表名 drop 字段名;

alter table teacher drop 年龄;

4.修改字段
用法:
alter table 表名 modify 字段名 数据类型[完整性约束条件…];
alter table 表名 change 旧字段名 新字段名 旧字段类型[完整性约束条件…]
alter table 表名 change 旧字段名 新字段名 新数据类型[完整性约束条件…]

alter table teacher modify 年龄 int;
alter table teacher change 年龄 age int;
alter table teacher change age 年龄 tinyint;

修改表的存储引擎

alter table service  engine=innodb;  

增加约束(针对已有的主键增加auto_increment)

alter table teacher modify id int not null auto_increment;

增加复合主键

alter table student add primary key(sid,身份证号码);	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值