LoginSignup
0
0

More than 5 years have passed since last update.

簡単なMySQLクエリのメモ

Posted at

XAMPPを使用しているのでまずcd /Applications/XAMPP/xamppfiles/binに移動
この後、データベース作成の練習で使用したクエリをメモしていきます。

データベースを作る

  • show databases;
    データベースの一覧を見ます。

  • use データベース名;
    show databases;で見られるデータベースの中で、選択したいもののところに移動します。

テーブルを作る

  • create table テーブル名 (); ()の中にはカンマ区切りでカラム名(半角スペース)型と記入します。 例はこのようになります。
Query
create table table1(
               id int,
               name varchar(128)
             );
  • alter table テーブル名 modify カラム名 型;
    テーブルを作る時に型の設定を間違えてしまった時の修正です。 間違えてしまったカラムの名前と、新しい型を書きます。

テーブルに中身を入れる

  • insert into テーブル名(id, name) values(数字, '文字');
    create tableで作ったテーブルに内容を1行ずつ挿入します。

  • select * from テーブル名;
    作成したテーブルの中身の確認です。

  • update テーブル名 set カラム名=新しい値 where 条件文;
    insertした内容が間違っていた時に使用します。

今回使用したのは以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0