-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.sql
55 lines (46 loc) · 1.53 KB
/
database.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
--CREATE DATABASE "ChatroomDB"
-- WITH
-- OWNER = postgres
-- ENCODING = 'UTF8'
-- LC_COLLATE = 'English_United States.1252'
-- LC_CTYPE = 'English_United States.1252'
-- TABLESPACE = pg_default
-- CONNECTION LIMIT = -1;
CREATE TABLE IF NOT EXISTS public."ChatRoom"
(
"RoomID" SERIAL,
"RoomName" text COLLATE pg_catalog."default" NOT NULL,
"Password" text COLLATE pg_catalog."default" NOT NULL,
"MessageHistory" text COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "ChatRoom_pkey" PRIMARY KEY ("RoomID")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."ChatRoom"
OWNER to postgres;
CREATE TABLE IF NOT EXISTS public."Users"
(
"UserID" SERIAL,
"UserName" text COLLATE pg_catalog."default" NOT NULL,
"Password" text COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT "Pk_Users" PRIMARY KEY ("UserID")
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."Users"
OWNER to postgres;
CREATE TABLE IF NOT EXISTS public."UserToChatrooms"
(
"UserID" integer NOT NULL,
"RoomID" integer NOT NULL,
CONSTRAINT "Pk_combined" PRIMARY KEY ("UserID", "RoomID"),
CONSTRAINT "FK_ChatRoom" FOREIGN KEY ("RoomID")
REFERENCES public."ChatRoom" ("RoomID") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT "FK_User" FOREIGN KEY ("UserID")
REFERENCES public."Users" ("UserID") MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."UserToChatrooms"
OWNER to postgres;