-
Notifications
You must be signed in to change notification settings - Fork 0
/
messenger.sql
38 lines (33 loc) · 1.18 KB
/
messenger.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
CREATE TABLE users (
ID INT NOT NULL PRIMARY KEY IDENTITY(0,1),
userName VARCHAR(50) NOT NULL,
isActive CHAR(1)
);
CREATE TABLE messagess (
messageID INT NOT NULL PRIMARY KEY IDENTITY(0,1),
content VARCHAR(150) NOT NULL,
createDate DATETIME NOT NULL,
);
CREATE TABLE groups (
groupId INT NOT NULL PRIMARY KEY IDENTITY(0,1),
groupName VARCHAR(150) NOT NULL,
createDate DATE NOT NULL,
isActive CHAR(1),
);
CREATE TABLE user_group (
userID INT NOT NULL FOREIGN KEY REFERENCES users(ID),
groupId INT NOT NULL FOREIGN KEY REFERENCES groups(groupID),
CONSTRAINT user_groupID PRIMARY KEY (userID, groupID)
);
CREATE TABLE user_to_user (
Id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
senderID INT NOT NULL FOREIGN KEY REFERENCES users(ID),
recieverID INT NOT NULL FOREIGN KEY REFERENCES users(ID),
messageID INT NOT NULL FOREIGN KEY REFERENCES messagess(messageID)
);
CREATE TABLE user_to_group (
Id INT NOT NULL PRIMARY KEY IDENTITY(0,1),
senderID INT NOT NULL FOREIGN KEY REFERENCES users(ID),
recieverID INT NOT NULL FOREIGN KEY REFERENCES groups(groupID),
messageID INT NOT NULL FOREIGN KEY REFERENCES messagess(messageID)
);