[升級須要用到的] 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…

相關文章
相關標籤/搜索