- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL_PGAdminFile.sql
More file actions
Latest commit
61 lines (50 loc) · 1.68 KB
/
Copy pathSQL_PGAdminFile.sql
File metadata and controls
61 lines (50 loc) · 1.68 KB
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
-- Exported from QuickDBD: https://www.quickdatabasediagrams.com/
-- Link to schema: https://app.quickdatabasediagrams.com/#/d/kYxqoF
-- NOTE! If you have used non-SQL datatypes in your design, you will have to change these here.
CREATETABLE "card_holder" (
"id"INTNOT NULL,
"name"VARCHAR(20) NOT NULL,
CONSTRAINT"pk_card_holder"PRIMARY KEY (
"id"
)
);
CREATETABLE "credit_card" (
"card"VARCHAR(20) NOT NULL,
"id_card_holder"INTNOT NULL,
CONSTRAINT"pk_credit_card"PRIMARY KEY (
"card"
)
);
CREATETABLE "merchant_category" (
"id"INTNOT NULL,
"name"VARCHAR(100) NOT NULL,
CONSTRAINT"pk_merchant_category"PRIMARY KEY (
"id"
)
);
CREATETABLE "merchant" (
"id"INTNOT NULL,
"name"VARCHAR(100) NOT NULL,
"id_merchant_category"INTNOT NULL,
CONSTRAINT"pk_merchant"PRIMARY KEY (
"id"
)
);
CREATETABLE "transaction" (
"id"INTNOT NULL,
"date"TIMESTAMPNOT NULL,
"amount" FLOAT NOT NULL,
"card"VARCHAR(20) NOT NULL,
"id_merchant"INTNOT NULL,
CONSTRAINT"pk_transaction"PRIMARY KEY (
"id"
)
);
ALTERTABLE"credit_card" ADD CONSTRAINT"fk_credit_card_id_card_holder"FOREIGN KEY("id_card_holder")
REFERENCES"card_holder" ("id");
ALTERTABLE"merchant" ADD CONSTRAINT"fk_merchant_id_merchant_category"FOREIGN KEY("id_merchant_category")
REFERENCES"merchant_category" ("id");
ALTERTABLE"transaction" ADD CONSTRAINT"fk_transaction_card"FOREIGN KEY("card")
REFERENCES"credit_card" ("card");
ALTERTABLE"transaction" ADD CONSTRAINT"fk_transaction_id_merchant"FOREIGN KEY("id_merchant")
REFERENCES"merchant" ("id");