mysql如何修改表字段的约束?

mysql如何修改表字段的约束


30秒到达战场
浏览 910回答 1
1回答

万千封印

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;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL