03 mysql中对表的操作

来源:互联网 发布:好看的古装网络电视剧 编辑:程序博客网 时间:2024/06/05 11:06

增加/删除字段

增加字段alter table table_name add [column] column_name column defination [first|after column_name]例子:alter table student add column stu_name varchar(32) not null default 'xxoo'删除列alter table student drop stu_name,drop stu_age,....

增加约束
mysql中的约束有这么几类
1,主键约束
2,唯一约束
3,外键约束
4,默认约束

alter table student add primary key (id) 

默认的索引类型为b-tree索引

alter table student add unique (stu_name,stu_age)

增加/删除默认约束

alter table student alter stu_name set default 'ooxx'alter table student alter stu_name drop default

删除主键约束

alter table student drop primary key;

删除唯一约束

alter table student drop index index_name
原创粉丝点击