-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.sql
59 lines (44 loc) · 1.4 KB
/
schema.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
CREATE DATABASE IF NOT EXISTS photoshare;
USE photoshare;
DROP TABLE IF EXISTS Albums CASCADE;
DROP TABLE IF EXISTS Pictures CASCADE;
DROP TABLE IF EXISTS Friends CASCADE;
DROP TABLE IF EXISTS Users CASCADE;
CREATE TABLE Users (
User_id int4 AUTO_INCREMENT,
First_name VARCHAR(30) NOT NULL,
Last_name VARCHAR(30) NOT NULL,
email varchar(255) UNIQUE,
password varchar(255),
Hometown VARCHAR(100),
Gender VARCHAR(10) NOT NULL,
Date_of_birth DATE NOT NULL,
constraint chk1 check (Gender = 'F' or Gender = 'M' or Gender = 'other'),
CONSTRAINT users_pk PRIMARY KEY (User_id)
);
CREATE TABLE Albums(
Album_id INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
Date_of_creation DATETIME NOT NULL,
user_id INTEGER,
FOREIGN KEY (user_id) REFERENCES Users(user_id)
);
CREATE TABLE Pictures
(
picture_id int4 AUTO_INCREMENT,
User_id int4,
imgdata longblob ,
caption VARCHAR(255),
INDEX upid_idx (User_id),
CONSTRAINT pictures_pk PRIMARY KEY (picture_id)
);
CREATE TABLE Friends(
Friends_id INTEGER PRIMARY KEY,
First_name VARCHAR(30),
Last_name VARCHAR(30),
User_id int4 AUTO_INCREMENT,
constraint fk_User
FOREIGN KEY (User_id) REFERENCES Users(User_id)
);
-- INSERT INTO Users (email, password) VALUES ('test@bu.edu', 'test');
-- INSERT INTO Users (email, password) VALUES ('test1@bu.edu', 'test');