This repository has been archived by the owner on Jun 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.sql
155 lines (126 loc) · 3.49 KB
/
chat.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- https://www.phpmyadmin.net/
--
-- 主机: 127.0.0.1
-- 生成日期: 2020-05-18 16:36:08
-- 服务器版本: 10.4.11-MariaDB
-- PHP 版本: 7.4.4
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- 数据库: `chat`
--
CREATE DATABASE IF NOT EXISTS `chat` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
USE `chat`;
-- --------------------------------------------------------
--
-- 表的结构 `chatmessage`
--
DROP TABLE IF EXISTS `chatmessage`;
CREATE TABLE `chatmessage` (
`mid` int(11) NOT NULL,
`cid` int(11) NOT NULL,
`from_uid` int(11) DEFAULT NULL,
`from_name` varchar(50) NOT NULL,
`message` text NOT NULL,
`time` datetime NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- 表的结构 `chatroom`
--
DROP TABLE IF EXISTS `chatroom`;
CREATE TABLE `chatroom` (
`cid` int(11) NOT NULL,
`type` tinyint(4) NOT NULL,
`group_number` int(4) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- 表的结构 `chatroom_user`
--
DROP TABLE IF EXISTS `chatroom_user`;
CREATE TABLE `chatroom_user` (
`cid` int(11) NOT NULL,
`uid` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- 表的结构 `user`
--
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`uid` int(11) NOT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(100) NOT NULL,
`last_online` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--
-- 转储表的索引
--
--
-- 表的索引 `chatmessage`
--
ALTER TABLE `chatmessage`
ADD PRIMARY KEY (`mid`),
ADD KEY `cid` (`cid`),
ADD KEY `from_uid` (`from_uid`);
--
-- 表的索引 `chatroom`
--
ALTER TABLE `chatroom`
ADD PRIMARY KEY (`cid`);
--
-- 表的索引 `chatroom_user`
--
ALTER TABLE `chatroom_user`
ADD PRIMARY KEY (`cid`,`uid`),
ADD KEY `uid` (`uid`);
--
-- 表的索引 `user`
--
ALTER TABLE `user`
ADD PRIMARY KEY (`uid`);
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `chatmessage`
--
ALTER TABLE `chatmessage`
MODIFY `mid` int(11) NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `chatroom`
--
ALTER TABLE `chatroom`
MODIFY `cid` int(11) NOT NULL AUTO_INCREMENT;
--
-- 使用表AUTO_INCREMENT `user`
--
ALTER TABLE `user`
MODIFY `uid` int(11) NOT NULL AUTO_INCREMENT;
--
-- 限制导出的表
--
--
-- 限制表 `chatmessage`
--
ALTER TABLE `chatmessage`
ADD CONSTRAINT `chatmessage_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `chatroom` (`cid`) ON DELETE CASCADE,
ADD CONSTRAINT `chatmessage_ibfk_2` FOREIGN KEY (`from_uid`) REFERENCES `user` (`uid`) ON DELETE SET NULL;
--
-- 限制表 `chatroom_user`
--
ALTER TABLE `chatroom_user`
ADD CONSTRAINT `chatroom_user_ibfk_1` FOREIGN KEY (`cid`) REFERENCES `chatroom` (`cid`) ON DELETE CASCADE,
ADD CONSTRAINT `chatroom_user_ibfk_2` FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON DELETE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;