Mysql表结构修改

来源:互联网 发布:网络是个虚拟世界英语 编辑:程序博客网 时间:2024/06/08 12:00

修改场景
创建了一个表但是忘记把主键设置为 自增长

 Create table `work_info` (  `work_id` int(11) NOT NULL,  `company` varchar(64) DEFAULT NULL,  `position` varchar(32) DEFAULT NULL,  `duty` varchar(128) DEFAULT NULL,  `departure` varchar(64) DEFAULT NULL,  `user_id` int(11) NOT NULL,  primary key (`work_id`),  key `fk_workinfo_account` (`user_id`),  constraint `fk_workinfo_account` foreign key (`user_id`) references `account` (`id`)) engine=InnoDB DEFAULT charset=utf8

把某一字段设置为自增长方法:

alter table work_info modify work_id int auto_increment;
alter table 表名 modify 字段名 int auto_increment;

修改某一字段允许为null:

alter table work_info modify user_id int null;--语法:alter  table  tableName  modify columnName  type  null;