データベース基礎

SQLとは

RB(リレーショナルデータベース)を操作するための言語

 

SQL分類の種類

DML(Data Manipulation Language)

データ操作

select・insert・update・delete

 

DDL(Data Definition Language)

データ定義

Create Database・Drop Databese・Create User・Drop User

Create Table・Drop Table

 

DCL(Data Control Language)

データ制御

Start Trasction・Commit・Rollback・Grant・Revoke

 

DML

select データ取得

insert データ登録

update データ修正

delete データ削除

 

DDL

CreateDetabese データベース作成

DropDatabese データベース削除

CreateUser ユーザ作成

DropUser ユーザ削除

CreateTable テーブル作成

DropTable デーブル削除

 

ユーザ作成

Grant All → 権限付与

 

テーブル作成

(ex)

Create table user-table(

      user_id INT,

      user_name VARCHAR(50),

      tel_no VRCHAR(50)

);

 

データ登録

insert文(DML

(ex)

insert into user_table values

(1,'田中','0311112222');

 

データ操作基本言語(DML基礎)

select文

(ex)

select * from user_table;

選択する 全て 〜から ユーザテーブル

*→全てのカラム

select user_name from user_table;

選択 ユーザネームを 〜から ユーザテーブル

where user_id=1;

ただし user_idが1のみ

 

insert文

(ex)

insert into user_table

values (10,'伊藤','0122223333');

カラム指定なし

insert into user_table

(user_id,user_name) values

(20,'高橋');

カラム指定あり

 

update文

(ex)

update user_table

set tel_no='111122223'

where user_id = 10;

whereで条件指定しないと変更するカラムを全更新してしまうので注意!

 

delete文

(ex)

delete from uer_table

where user_id = 10;

 whereで条件指定しないと変更するカラムを全更新してしまうので注意!

 

比較演算子

A=x Aとxは等しい

A!=x Aとxは等しくない

A<>x Aとxは等しくない

A>x Aはxより大きい

A<x Aはxより小さい

A>=x Aはx以上

A<=x Aはx以下

A in(x,y) Aがxかyである

A is null Aがnullである

 

論理演算子

A AND B AかつB

A OR B AまたはB