コマンドプロンプトからMySQLのデータを修正する場合
2009 年 3 月 13 日 金曜日フィールド名と属性を変更する
型:alter table テーブル名 change 旧フィールド名 新フィールド名 型;
例:alter table tablename change fieldname1 fildname2 char(255);
フィールドの属性のみ変更する
型:alter table テーブル名 modify フィールド名 新しい属性;
例:alter table tablename modify fieldname1 char(255);
フィールドの追加
型:alter table テーブル名 add フィールド名 属性;
例:alter table tablename add fieldnamex int;
テーブルの削除
型:drop table テーブル名;
例:drop table tablename;
レコードの作成
型:insert into テーブル名 values ('文字列の場合',数字の場合,…);
例:insert into tablename values ('MySQL',255);
※フィールドの数分入力しないと ERROR 1136 (21S01): Column count doesn't match value count at row 1のように表示される。
レコード挿入1
型:select * from テーブル名;
例:select * from tablename;
レコード挿入2
型:insert into テーブル名 (フィールド名,…) values (フィールド名の値,…);
例:insert into tablename (MySQL) values (5.0);
※入力のないフィールド部分はNULLが挿入される。
特定のフィールドだけ表示
型:select フィールド名 from テーブル名;
例:select fieldname,… from tablename;
複数の条件検索
型:select * from テーブル名 where フィールド名 検索条件 and フィールド名 検索条件
例:select * from tablename where fieldname1 like '%文字列%' and filedname2 > 数値;
※フィールド1の中で文字列から始まり、且つ、フィールド2の中で 数値より大きい
型:select * from テーブル名 where フィールド名 検索条件 or フィールド名 検索条件
例:select * from tablename where fieldname1 like '%文字列%' or filedname2 > 数値;
※フィールド1の中で文字列から始まり、又は、フィールド2の中で 数値より大きい
