LoginSignup
0
0

More than 3 years have passed since last update.

MySQLのデータベース、テーブルの作成と削除、行の追加

Last updated at Posted at 2020-09-23

データベース作成

create database shop;

データベース一覧

show databases;

データベース削除

 drop database shop;

テーブル作成

create table Shohin (
    shohin_id varchar(4) not null primary key,
    shohin_mei varchar(100) not null,
    shohin_bunrui varchar(32) not null,
    hanbai_tanka int,
    shiire_tanka int,
    torokubi DATE
    );

テーブル一覧

show tables;

テーブル削除

drop table Shohin;

データ追加

insertの後のintoは省略可能。
また、全てのカラムに対してデータを登録する場合、カラム名の指定を省略可能。

-- into,カラム名を省略したバージョン
insert Shohin values ('0001', 'Tシャツ', '衣服', 1000, 500, '2009-09-20');

-- 特定のカラムのみデータを登録する場合、valuesの前に対象のカラムを記述する
-- 指定されていないカラムについてはnullが入る
insert Shohin (shohin_id, shohin_mei, shohin_bunrui) values ('9999', '技術書', '経験値');

データ削除

delete from Shohin where shohin_id = 9999;
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