mysql 基本構文1 | 東京都練馬区行政書士のジュウダ日記

mysql 基本構文1

基本構文

1:  create databases データベース名;

2:  show databases;

3:  use データベース名;

4:  create table テーブル名 (フィールド名1 データ型, フィールド名2 データ型, ・・・・・・・・);

5:  show tables;

6:  show fields from テーブル名;

7:  alter table テーブル名 change 旧フィールド名 新フィールド名 型;

8:  alter table テーブル名 modify フィールズ名 新しい属性;

9:  alter table テーブル名 add 追加するフィールド名 その属性;

10: drop table テーブル名;

11: insert into テーブル名 values (フィールド1の値, フィールド2の値・・・・・・・);

12: insert into テーブル名 (フィールド名1, フィールド名2・・・・・) values(フィールド名1の値, フィールド名2・・・・);

13: select 表示対象フィールド from テーブル名 where 条件式;

14: update テーブル名 set フィールド名 = 修正したい値 where 条件式;

15: delete from テーブル名 where 条件;

16: load data infile "テキストファイル名" into table テーブル名;

17: select 表示したいフィールド from テーブル名 order by フィールド名;

18: select 表示したいフィールド from テーブル名 order by フィールド名 desc;

19: select 表示したいフィールド from テーブル名 order by menseki desc limit 10;


[自動連番]

(1) alter table テーブル名 add 連番フィールド int;

(2) alter table テーブル名 add index インデックス名(連番フィールド);

(3) alter table テーブル名 modify 連番フィールド int auto_increment;


[PHP mysql関数]

・extract($_POST);

・extract($_GET);

・mysql_connect('ホスト名', 'ユーザ名', 'パスワード');

・mysql_select_db('データベース名');

・mysql_query($mysql);

・mysql_num_rows($result);

・mysql_fetch_array($result)