-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_w2016.sql
70 lines (62 loc) · 1.62 KB
/
setup_w2016.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
/*
* File name: setup.sql
* Function: to create the initial database schema for the CMPUT 391 project: An Online Image Sharing System
* Winter, 2016
* Author: Prof. Li-Yan Yuan
*/
DROP TABLE images;
DROP TABLE group_lists;
DROP TABLE groups;
DROP TABLE persons;
DROP TABLE users;
CREATE TABLE users (
user_name varchar(24),
password varchar(24),
date_registered date,
primary key(user_name)
);
CREATE TABLE persons (
user_name varchar(24),
first_name varchar(24),
last_name varchar(24),
address varchar(128),
email varchar(128),
phone char(10),
PRIMARY KEY(user_name),
UNIQUE (email),
FOREIGN KEY (user_name) REFERENCES users
);
CREATE TABLE groups (
group_id int,
user_name varchar(24),
group_name varchar(24),
date_created date,
PRIMARY KEY (group_id),
UNIQUE (user_name, group_name),
FOREIGN KEY(user_name) REFERENCES users
);
INSERT INTO groups values(1,null,'public', sysdate);
INSERT INTO groups values(2,null,'private',sysdate);
CREATE TABLE group_lists (
group_id int,
friend_id varchar(24),
date_added date,
notice varchar(1024),
PRIMARY KEY(group_id, friend_id),
FOREIGN KEY(group_id) REFERENCES groups,
FOREIGN KEY(friend_id) REFERENCES users
);
CREATE TABLE images (
photo_id int,
owner_name varchar(24),
permitted int,
subject varchar(128),
place varchar(128),
timing date,
description varchar(2048),
thumbnail blob,
photo blob,
PRIMARY KEY(photo_id),
FOREIGN KEY(owner_name) REFERENCES users,
FOREIGN KEY(permitted) REFERENCES groups
);