-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_diagram.sql
78 lines (60 loc) · 1.99 KB
/
database_diagram.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
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/Ryeyie
CREATE TABLE "category" (
"category_id" varchar NOT NULL,
"category" varchar NOT NULL,
CONSTRAINT "pk_category" PRIMARY KEY (
"category_id"
)
);
CREATE TABLE "subcategory" (
"subcategory_id" varchar NOT NULL,
"subcategory" varchar NOT NULL,
CONSTRAINT "pk_subcategory" PRIMARY KEY (
"subcategory_id"
)
);
CREATE TABLE "campaign_df" (
"cf_id" int NOT NULL,
"contact_id" int NOT NULL,
"company_name" varchar NOT NULL,
"description" varchar NOT NULL,
"goal" float NOT NULL,
"pledged" float NOT NULL,
"outcome" varchar NOT NULL,
"backers_count" int NOT NULL,
"country" varchar NOT NULL,
"currency" varchar NOT NULL,
"launch_date" date NOT NULL,
"end-date" date NOT NULL,
"category_id" varchar NOT NULL,
"subcategory_id" varchar NOT NULL,
CONSTRAINT "pk_campaign_df" PRIMARY KEY (
"cf_id"
)
);
CREATE TABLE "contacts_df" (
"contact_id" int NOT NULL,
"first_name" varchar NOT NULL,
"last_name" varchar NOT NULL,
"email" varchar NOT NULL,
CONSTRAINT "pk_contacts_df" PRIMARY KEY (
"contact_id"
)
);
-- foreign key constraints
ALTER TABLE "campaign_df" ADD CONSTRAINT "fk_campaign_df_contact_id" FOREIGN KEY("contact_id")
REFERENCES "contacts_df" ("contact_id");
ALTER TABLE "campaign_df" ADD CONSTRAINT "fk_campaign_df_category_id" FOREIGN KEY("category_id")
REFERENCES "category" ("category_id");
ALTER TABLE "campaign_df" ADD CONSTRAINT "fk_campaign_df_subcategory_id" FOREIGN KEY("subcategory_id")
REFERENCES "subcategory" ("subcategory_id");
-- verify all csv data imported with select all queries:
SELECT *
FROM campaign_df;
SELECT *
FROM category;
SELECT *
FROM subcategory;
SELECT *
FROM contacts_df;