-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrowdfunding_db_schema.sql
78 lines (57 loc) · 1.75 KB
/
crowdfunding_db_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
This script creates a database with four tables for use in a fictional Crowdfunding exercise
'not null' constraints are not applied on fields because data elements may not be known
at the time of record creation. By default, PK is nt null.
The 'category_id' is set to 5 variable characters to allow for growth, in the evemt another recrd is added. There are currently 9 values, so adding the additional length of one character allows growth to 99 rows total before an alter table command would be required.
author: Adrian Santos
updated: 2013-12-02
*/
--------------------------------------
/* Create database */
--------------------------------------
create database crowdfunding_db
with
owner = postgres
encoding = 'UTF8'
lc_collate = 'C'
lc_ctype = 'C'
tablespace = pg_default
connection limit = -1
is_template = false
;
--------------------------------------
/* Create tables */
--------------------------------------
create table contacts (
contact_id char(4) primary key
, first_name varchar(256)
, last_name varchar(256)
, email varchar(256)
);
create table category (
category_id varchar(5) primary key
, category varchar(256)
);
create table subcategory (
subcategory_id varchar(8) primary key
, subcategory varchar(256)
);
create table campaign (
cf_id varchar(4) primary key
, contact_id char(4)
, company_name varchar(256)
, description varchar(256)
, goal float
, pledged float
, outcome varchar(10)
, backers_count int
, country char(2)
, currency char(3)
, launch_date date
, end_date date
, category_id varchar(5)
, subcategory_id varchar(8)
, foreign key (contact_id) references contacts (contact_id)
, foreign key (category_id) references category (category_id)
, foreign key (subcategory_id) references subcategory (subcategory_id)
);