SQLコマンド基本まとめ
挿入
insert into A_TABLE(NAME,TIME) values('test',SYSDATE);
insert into A_TABLE values('test',14,SYSDATE);
※全項目を指定する場合は項目名を入れなくても良い
更新
update A_TABLE set AGE=23, TIME=SYSDATE where NAME='test';
削除
delete from A_TABLE where NAME='test';
選択
全
sele
項
sele
条件指定
(例)n
sele
(例)a
sele
(例)n
sele
(例)n
sele
'%奈'だと末尾
指定件数
sele
新しいデ
(例)項
sele
desc
文字→時間
to_date('20140101100000','yyyymmddhh24miss')
時間→文字
to_char(TIME,'yyyy/mm/dd hh24:mi:ss')
テーブル定義確認
show databases;
show tables;
show tbles like '%item%';
show create table テーブル名;
desc テーブル名;
テーブル作成
create table A_TABLE(
NAME varchar(20) not null,
AGE int,
TIME date,
primary key(NAME)
);
テーブル定義変更
カラム名変更
alter table テーブル名 change 古カラム名 新カラム名 int;
カラム定義変更
alter table テーブル名 modify カラム名 tinyint;
カラム追加(afterで追加位置指定)
alter table テーブル名 add 追加カラム名 int after カラム名;
カラム削除
alter table テーブル名 drop column カラム名;
テーブル削除
drop table テーブル名;
テーブル初期化(deleteより圧倒的に早い)
truncate テーブル名