-- 将sid移动到第一行 alter table student modify sid int first; -- 将sage移动到ssex后面 alter table student modify sage int not null after ssex; -- 添加删除主键 alter table student add primary key(sid); alter table student drop primary key; -- 添加删除唯一约束1 alter table student add unique(sname); alter table student drop index sname; alter table student drop key sname; -- 添加唯一性约束2 alter table student add constraint uk unique key student(sname); -- 添加联合唯一索引 alter table student add constraint double_uk unique index double_uk1(sname,ssex); -- 添加删除自增 alter table student modify sid int auto_increment; alter table student modify sid int; -- 添加删除外键 alter table student add constraint fk1 foreign key(sphone) references teacher(tid); alter table student drop foreign key fk1; -- 添加删除非空约束 alter table student modify sage int not null; alter table student modify sage int; -- 修改字段名称及属性 alter table student change sssex ssex char(2) default '男'; -- 添加删除默认值 alter table student modify sssex char(2) default '男'; alter table student modify sssex char(2); -- 查看表结构 describe student; -- 查看索引 show keys from student; -- 查看表源码 show create table student; -- 修改表的存储引擎 -- ALTER TABLE tb_name ENGINE=存储引擎名称 ALTER TABLE user12 ENGINE=MyISAM; -- 修改自增长的值 -- ALTER TABLE tb_name AUTO_INCREMENT=值 ALTER TABLE user12 auto_increment=100; -- 如果表存在就删除 drop table if exists tablename;