· 9 years ago · Jan 05, 2017, 03:30 PM
1-- WP32 課題9 サãƒãƒ¼ãƒˆãƒ•ァイル
2--
3-- テーブル作æˆã€ãƒ‡ãƒ¼ã‚¿ç™»éŒ²SQLファイル
4-- sharerepousrユーザã§ä½¿ç”¨
5-- コマンド: mysql -u sharerepousr -p sharerepo --default-character-set=utf8 < "/…/2015WP32Asgmt09_dbinit_UTF8.sql"
6--
7-- @author Shinzo SAITO
8
9-- テーブル削除
10DROP TABLE IF EXISTS users;
11DROP TABLE IF EXISTS reports;
12DROP TABLE IF EXISTS reportcates;
13
14-- ユーザ
15CREATE TABLE users
16(
17 id int NOT NULL AUTO_INCREMENT COMMENT 'ユーザID',
18 us_mail text NOT NULL COMMENT 'メールアドレス',
19 us_name text NOT NULL COMMENT 'åå‰',
20 us_password text NOT NULL COMMENT 'パスワード',
21 -- 0=終了
22 -- 1=管ç†è€…
23 -- 2=一般
24 us_auth int DEFAULT 2 NOT NULL COMMENT 'æ¨©é™ : 0=終了
251=管ç†è€…
262=一般',
27 PRIMARY KEY (id)
28) COMMENT = 'ユーザ';
29
30-- レãƒãƒ¼ãƒˆ
31CREATE TABLE reports
32(
33 id int NOT NULL AUTO_INCREMENT COMMENT 'レãƒãƒ¼ãƒˆID',
34 rp_date date NOT NULL COMMENT 'ä½œæ¥æ—¥',
35 rp_time_from time NOT NULL COMMENT '作æ¥é–‹å§‹æ™‚é–“',
36 rp_time_to time NOT NULL COMMENT '作æ¥çµ‚了時間',
37 rp_content text NOT NULL COMMENT '作æ¥å†…容',
38 rp_created_at datetime NOT NULL COMMENT '登録日時',
39 reportcate_id int NOT NULL COMMENT '作æ¥ç¨®é¡žID',
40 user_id int NOT NULL COMMENT 'å ±å‘Šè€…ID',
41 PRIMARY KEY (id)
42) COMMENT = 'レãƒãƒ¼ãƒˆ';
43
44-- 作æ¥ç¨®é¡ž
45CREATE TABLE reportcates
46(
47 id int NOT NULL AUTO_INCREMENT COMMENT '作æ¥ç¨®é¡žID',
48 rc_name text NOT NULL COMMENT '種類å',
49 rc_note text COMMENT '備考',
50 -- 0=éžè¡¨ç¤º
51 -- 1=表示
52 rc_list_flg int DEFAULT 1 NOT NULL COMMENT 'ãƒªã‚¹ãƒˆè¡¨ç¤ºã®æœ‰ç„¡ : 0=éžè¡¨ç¤º
531=表示',
54 rc_order int DEFAULT 0 NOT NULL COMMENT 'è¡¨ç¤ºé †åº',
55 PRIMARY KEY (id)
56) COMMENT = '作æ¥ç¨®é¡ž';
57
58-- 外部ã‚ー作æˆ(reports-reportcates)
59ALTER TABLE reports
60 ADD FOREIGN KEY (reportcate_id)
61 REFERENCES reportcates (id)
62 ON UPDATE CASCADE
63 ON DELETE CASCADE
64;
65
66-- 外部ã‚ー作æˆ(reports-users)
67ALTER TABLE reports
68 ADD FOREIGN KEY (user_id)
69 REFERENCES users (id)
70 ON UPDATE CASCADE
71 ON DELETE CASCADE
72;
73
74
75-- ユーザデータ挿入
76INSERT INTO users (us_mail, us_name, us_password, us_auth) VALUES ('architshin@websarva.com', '齊藤新三', 'hogehoge', '1');
77
78-- 作æ¥ç¨®é¡žãƒ‡ãƒ¼ã‚¿æŒ¿å…¥
79INSERT INTO reportcates (rc_name, rc_note, rc_list_flg, rc_order) VALUES ('実装', '', '1', '1');
80INSERT INTO reportcates (rc_name, rc_note, rc_list_flg, rc_order) VALUES ('打åˆã›', '', '1', '2');
81INSERT INTO reportcates (rc_name, rc_note, rc_list_flg, rc_order) VALUES ('資料作æˆ', '', '1', '3');
82INSERT INTO reportcates (rc_name, rc_note, rc_list_flg, rc_order) VALUES ('顧客対応', '', '1', '4');
83INSERT INTO reportcates (rc_name, rc_note, rc_list_flg, rc_order) VALUES ('è¨è¨ˆ', '', '1', '5');
84INSERT INTO reportcates (rc_name, rc_note, rc_list_flg, rc_order) VALUES ('ãã®ä»–', '', '1', '6');