質問編集履歴
1
sql分の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -510,6 +510,62 @@
|
|
510
510
|
|
511
511
|
```
|
512
512
|
|
513
|
+
#作成したテーブル
|
514
|
+
|
515
|
+
```sql
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
--ユーザーテーブル--
|
520
|
+
|
521
|
+
CREATE TABLE IF NOT EXISTS user(
|
522
|
+
|
523
|
+
user_id INTEGER AUTO_INCREMENT,
|
524
|
+
|
525
|
+
user_name VARCHAR(12) NOT NULL,
|
526
|
+
|
527
|
+
PRIMARY KEY(user_id);
|
528
|
+
|
529
|
+
) ENGINE=INNODB DEFAULT CHARSET=utf8;
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
--メッセージテーブル--
|
534
|
+
|
535
|
+
CREATE TABLE IF NOT EXISTS message(
|
536
|
+
|
537
|
+
message_id BIGINT AUTO_INCREMENT NOT NULL,
|
538
|
+
|
539
|
+
sender_user_id INTEGER NOT NULL,
|
540
|
+
|
541
|
+
receiver_user_id INTEGER NOT NULL,
|
542
|
+
|
543
|
+
message_content VARCHAR(300),
|
544
|
+
|
545
|
+
message_time datetime DEFAULT CURRENT_TIMESTAMP,
|
546
|
+
|
547
|
+
PRIMARY KEY(message_id),
|
548
|
+
|
549
|
+
FOREIGN KEY (sender_user_id)
|
550
|
+
|
551
|
+
REFERENCES user(user_id)
|
552
|
+
|
553
|
+
ON DELETE CASCADE,
|
554
|
+
|
555
|
+
FOREIGN KEY (receiver_user_id)
|
556
|
+
|
557
|
+
REFERENCES user(user_id)
|
558
|
+
|
559
|
+
ON DELETE CASCADE
|
560
|
+
|
561
|
+
) ENGINE=INNODB DEFAULT CHARSET=utf8;
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
|
566
|
+
|
567
|
+
```
|
568
|
+
|
513
569
|
#ER図
|
514
570
|
|
515
571
|
![イメージ説明](d5b694ec1e8ee1668ff657a6acc68fdd.png)
|