MySQL002 コマンド2 (alter table)
mysql コマンド2
alter table tableName [modify/add/change/drop] ~
■chap5:データ型とデータ入力
データ型
1.数値
int, tinyint, smallint, mediumint,bigint,float,double,decimal
暫定:整数はint、小数点以下含むものはdoubleを利用
2.文字列
char,varchar,text,longtext
暫定:255文字以下はvarchar、それ以上はtextを利用
3.日付・時刻型
date time, date, year, time
■chap6:カラム構造の変更
1.カラムの定義変更 modify ※既存データの消滅に注意
○データ型
alter table tb1 modify age int(3);
○カラム位置
alter table tb1 modify age int(3) first;
2.カラムの追加 add
○最後
alter table tb1 add birthday datetime;
→insert into tb1 values('emp006','八九寺',10,2001-8-7);→ミス
→update db1.tb1 set birthday='2007-8-7' where num='emp006';
○先頭(first)
alter table tb1 add firstClm varchar(10) first;
○好きな位置(after)
alter table tb1 add freePositionClm varchar(10) after firstClm;
3.カラムの名前+定義変更 change
alter table tb1 change birthday birth date;
4.カラムの削除 drop
alter table tb1 drop firstClm;
alter table tb1 drop freePositionClm;
■参考
本:基礎からのMySQL