-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrowdfunding_db_schema.sql
76 lines (65 loc) · 2.39 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
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- Link to schema: https://app.quickdatabasediagrams.com/
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
CREATE TABLE "campaign" (
"cf_id" int NOT NULL,
"contact_id" int NOT NULL,
"company_name" varchar(100) NOT NULL,
"description" text NOT NULL,
"goal" numeric(10,2) NOT NULL,
"pledged" numeric(10,2) NOT NULL,
"outcome" varchar(50) NOT NULL,
"backers_count" int NOT NULL,
"country" varchar(10) NOT NULL,
"currency" varchar(10) NOT NULL,
"launch_date" date NOT NULL,
"end_date" date NOT NULL,
"category_id" varchar(10) NOT NULL,
"subcategory_id" varchar(10) NOT NULL,
CONSTRAINT "pk_campaign" PRIMARY KEY (
"cf_id"
)
);
CREATE TABLE "category" (
"category_id" varchar(10) NOT NULL,
"category_name" varchar(50) NOT NULL,
CONSTRAINT "pk_category" PRIMARY KEY (
"category_id"
)
);
CREATE TABLE "subcategory" (
"subcategory_id" varchar(10) NOT NULL,
"subcategory_name" varchar(50) NOT NULL,
CONSTRAINT "pk_subcategory" PRIMARY KEY (
"subcategory_id"
)
);
CREATE TABLE "contacts" (
"contact_id" int NOT NULL,
"first_name" varchar(50) NOT NULL,
"last_name" varchar(50) NOT NULL,
"email" varchar(100) NOT NULL,
CONSTRAINT "pk_contacts" PRIMARY KEY (
"contact_id"
)
);
CREATE TABLE "backers" (
"backer_id" varchar(10) NOT NULL,
"cf_id" int NOT NULL,
"first_name" varchar(50) NOT NULL,
"last_name" varchar(50) NOT NULL,
"email" varchar(100) NOT NULL,
CONSTRAINT "pk_backers" PRIMARY KEY (
"backer_id"
)
);
ALTER TABLE "category" ADD CONSTRAINT "fk_category_category_id" FOREIGN KEY("category_id")
REFERENCES "campaign" ("category_id");
ALTER TABLE "subcategory" ADD CONSTRAINT "fk_subcategory_subcategory_id" FOREIGN KEY("subcategory_id")
REFERENCES "campaign" ("subcategory_id");
ALTER TABLE "contacts" ADD CONSTRAINT "fk_contacts_contact_id" FOREIGN KEY("contact_id")
REFERENCES "campaign" ("contact_id");
ALTER TABLE "backers" ADD CONSTRAINT "fk_backers_cf_id" FOREIGN KEY("cf_id")
REFERENCES "campaign" ("cf_id");