Skip to content

13.DB(MySQL)の準備

domanthan edited this page Jun 22, 2020 · 3 revisions

データベース作成

mysql> create database calendar;
mysql> use calendar
mysql> 

テーブル作成

CREATE TABLE calendar.Holiday (
    id INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
    year int,
    month int,
    day int,
    name text
);

mysql> describe holiday;

結果例:

+-------+------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra          |
+-------+------+------+-----+---------+----------------+
| id    | int  | NO   | PRI | NULL    | auto_increment |
| year  | int  | YES  |     | NULL    |                |
| month | int  | YES  |     | NULL    |                |
| day   | int  | YES  |     | NULL    |                |
| name  | text | YES  |     | NULL    |                |
+-------+------+------+-----+---------+----------------+
5 rows in set (0.01 sec)


mysql> 

データの準備

INSERT INTO `Holiday` (`year`, `month`, `day`, `name`) 
VALUES (2020,1,13,'成人の日'),
(2020,2,11,'建国記念の日'),
(2020,2,23,'天皇誕生日'),
(2020,2,24,'振替休日'),
(2020,3,20,'春分の日'),
(2020,4,29,'昭和の日'),
(2020,5,3,'憲法記念日'),
(2020,5,4,'振替休日'),
(2020,5,4,'みどりの日'),
(2020,5,5,'こどもの日'),
(2020,7,20,'海の日'),
(2020,8,11,'山の日'),
(2020,9,21,'敬老の日'),
(2020,9,22,'秋分の日'),
(2020,10,12,'体育の日'),
(2020,11,3,'文化の日'),
(2020,11,23,'勤労感謝の日');

mysql> select * from holiday;

+----+------+-------+------+-----------+
| id | year | month | day  | name      |
+----+------+-------+------+-----------+
|  1 | 2020 |     8 |   11 | 山の日    |
|  2 | 2020 |     8 |   12 | 海の日    |
+----+------+-------+------+-----------+
.......


mysql> commit;   

Clone this wiki locally