Mysqlフィールド変更
7260 ワード
新規フィールド
構文:alter tableテーブル名add列名フィールドタイプ;例:
フィールドの変更
構文:alter tableテーブル名change古いフィールド新しいフィールド新しいフィールドタイプ;例:
構文:alter tableテーブル名modify columnフィールド名タイプの例:
フィールドの削除
構文:alter tableテーブル名drop列名;例:
索引の追加
構文:alter tableテーブル名add indexインデックス名(カラム名1、カラム名2、カラム名3)
索引の削除
構文:drop indexインデックス名onテーブル名alter tableテーブル名drop indexインデックス名
構文:alter tableテーブル名add列名フィールドタイプ;例:
alter table message add message_type tinyint(4);
alter table message add message_type tinyint(4) not null comment ' ';
フィールドの変更
構文:alter tableテーブル名change古いフィールド新しいフィールド新しいフィールドタイプ;例:
alter table message change message_type msg_type tinyint(20);
alter table message change message_type msg_type tinyint(20) not null comment ' ';
構文:alter tableテーブル名modify columnフィールド名タイプの例:
alter table message modify column poi_lon decimal(10,6);
alter table message modify column poi_lon decimal(10,6) default null comment ' ';
フィールドの削除
構文:alter tableテーブル名drop列名;例:
alter table message drop latLon_type;
索引の追加
構文:alter tableテーブル名add indexインデックス名(カラム名1、カラム名2、カラム名3)
alter table table_name add index index_name (column_list);
alter table table_name add unique (column_list);
alter table table_name add primary key (column_list);
alter table conv_user add unique key idx_conv_user_id (conv_id,user_id) using btree comment ' ID、 ID ';
alter table conv_user add key idx_user_id (user_id) using hash comment ' ID ';
alter table friend_relation add index idx_user_id (user_id) using hash comment ' ID ';
alter table file_content add index idx_content (content(20)) using btree comment ' ( 20 )';
索引の削除
構文:drop indexインデックス名onテーブル名alter tableテーブル名drop indexインデックス名
drop index index_name on talbe_name;
alter table table_name drop index index_name;
alter table table_name drop primary key;