mysql如何修改表字段的约束
展开全部
1.增加字段:
alter table tablename add new_field_id type not null default '0';
例:
alter table mmanapp_mmanmedia add appid_id integer not null default 372;
增加主键:
alter table tabelname add new_field_id type default 0 not nullauto_increment ,add primary key (new_field_id);
增加外键:
在已经存在的字段上增加外键约束
ALTER TABLE yourtablename ADD [CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name, ...) REFERENCES tbl_name (index_col_name, ...) [ON DELETE {RESTRICT | CASCADE | SET NULL | NO ACTION}] [ON UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION}]
2.删除字段:
alter table tablename drop column colname;
例:
alter table mmanapp_mmanmedia drop column appid_id;
3.修改字段名:
alter table tablename change old_field_name new_field_name old_type;
4.修改字段类型:
alter table tablename change filed_name filed_name new_type;
alter table tablename add new_field_id type not null default '0';
例:
alter table mmanapp_mmanmedia add appid_id integer not null default 372;
增加主键:
alter table tabelname add new_field_id type default 0 not nullauto_increment ,add primary key (new_field_id);
增加外键:
在已经存在的字段上增加外键约束
ALTER TABLE yourtablename ADD [CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name, ...) REFERENCES tbl_name (index_col_name, ...) [ON DELETE {RESTRICT | CASCADE | SET NULL | NO ACTION}] [ON UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION}]
2.删除字段:
alter table tablename drop column colname;
例:
alter table mmanapp_mmanmedia drop column appid_id;
3.修改字段名:
alter table tablename change old_field_name new_field_name old_type;
4.修改字段类型:
alter table tablename change filed_name filed_name new_type;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |