Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

SQL 第2版 ゼロからはじめるデータベース操作1章

Last updated at Posted at 2020-06-10

#1章データベースとSQL

##データベース
まずはテーブルを格納するためのデータベースを作成する。

データベース作成

create database shop; 

データベース一覧

\l

データベース削除

drop database shop; 

##テーブル
ショップデータベースの中に商品テーブルを作成する。

テーブル作成

create table shohin
(shohin_id char(4) not null,
 shohin_mei char(100) not null,
 shohin_bunrui varchar(32) not null,
 hanbai_tanka integer, 
 shiire_tanka integer,
 torokubi     date,
 primary key (shohin_id) 
);

テーブル一覧

\dt;

テーブル削除

drop table shohin;

カラムの追加

alter table shohin add column shohin_mei_kana varchar(100);

カラムの削除

alter table shohin drop column shohin_mei_kana;

テーブル名の変更

alter tabel shohin rename to product;

データ挿入

  begin transaction;
  insert into shohin values ('0001','Tシャツ','衣服',1000,500,'2009-09-20'),
                            ('0002','穴あけパンチ','事務用品',500,320,'2009-09-11'),
                            ('0003','カッターシャツ','衣服',4000,2800),
                            ('0004','包丁','キッチン用品',3000,2800,'2009-09-20'),
                            ('0005','圧力鍋','キッチン用品',6800,5000,'2009-01-15'),
                            ('0006','フォーク','キッチン用品',500,null,'2009-09-20'),
                            ('0007','おろしがね','キッチン用品',880,790,'2009-04-28'),
                            ('0008','ボールペン','事務用品',100,null,'2009-11-11');
 commit;
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?