[升级须要用到的] mysql更新表 增长、删除、修改表字段

一、添加表字段.net

alter table tab1 add field_name varchar(10) default null comment 'xxx';blog

alter table tab1 add id int unsigned not null auto_increment primary key;rem

alter table tab1 add (field1 varchar(10), field2 varchar(20));get

二、修改表字段it

alter table tab1 modify column field_name; //修改一个字段的类型table

alter table user CHANGE new1 new4 int;  //修改一个字段的名称,此时必定要从新指定该字段的类型遍历

三、删除表字段im

alter table tab1 drop column field_name;tab

四、修改表名di

rename table old_tabname to new_tabname;

五、检查表字段 待补充... PS 检查表字段是否存在,存在就添加字段, 不存在不处理

六、遍历表字段

pragma table_info(old_tablename)

其中 old_tablename 是表格名,要遍历的表,另外须要存在 table_info 模型类 PS 遍历表全部存在字段,用于升级前检查

参考来源: blog.csdn.net/spirit_8023…

相关文章
相关标签/搜索