-
Notifications
You must be signed in to change notification settings - Fork 3
/
DDL.sql
241 lines (205 loc) · 6.22 KB
/
DDL.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
create schema investpro
set search_path to investpro
CREATE TABLE Users (
User_ID CHAR(10) PRIMARY KEY,
Pan_No CHAR(10) UNIQUE NOT NULL,
Email VARCHAR(50) UNIQUE NOT NULL,
Name CHAR(30) NOT NULL,
Contect_No CHAR(10) UNIQUE NOT NULL,
Available_Balance DECIMAL(10,2)
);
CREATE TABLE Account(
Account_No VARCHAR(16) PRIMARY KEY,
IFSC CHAR(11) UNIQUE NOT NULL,
User_ID CHAR(10) ,
FOREIGN KEY(User_ID) REFERENCES Users(User_ID)
ON UPDATE CASCADE
ON DELETE CASCADE
);
create table Bank_info(
IFSC CHAR(11) PRIMARY KEY REFERENCES account(IFSC)
ON UPDATE CASCADE,
bank_name VARCHAR(30) NOT NULL,
PRIMARY KEY(IFSC)
);
CREATE TABLE Transactions (
Transaction_ID CHAR(12) PRIMARY KEY,
Transaction_Time TIMESTAMP,
User_ID CHAR(10) ,
FOREIGN KEY(User_ID) REFERENCES Users(User_ID)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE Bank_Wallet (
Transaction_ID CHAR(12) REFERENCES Transactions(Transaction_ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
Bank_Acc_No VARCHAR(16) NOT NULL,
Amount DECIMAL(10,2) NOT NULL,
Transaction_Type VARCHAR(20) NOT NULL,
PRIMARY KEY(Transaction_ID)
);
CREATE TABLE Wallet_Stock(
Transaction_ID CHAR(12) ,
Stock_Symbol VARCHAR(30) ,
Order_Type VARCHAR(15) NOT NULL,
Qty VARCHAR(10) NOT NULL,
Buy_Price DECIMAL(10,2) NOT NULL,
Order_ID CHAR(10) ,
PRIMARY KEY(Transaction_ID),
FOREIGN KEY(Order_ID) REFERENCES Orders(Order_ID)
ON UPDATE CASCADE,
FOREIGN KEY(Transaction_ID) REFERENCES Transactions(Transaction_ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(Stock_Symbol) REFERENCES Stocks(Stock_Symbol)
ON UPDATE CASCADE
);
CREATE TABLE Watchlist (
User_ID CHAR(10) ,
Stock_Symbol VARCHAR(30) ,
PRIMARY KEY (User_ID,Stock_Symbol),
FOREIGN KEY(User_ID) REFERENCES Users(User_ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(Stock_Symbol) REFERENCES Stocks(Stock_Symbol)
ON UPDATE CASCADE
);
CREATE TABLE Holdings (
User_ID CHAR(10) ,
Stock_Symbol VARCHAR(30),
Purchase_Time TIMESTAMP,
Buy_Price DECIMAL(10,2) NOT NULL,
Qty INT NOT NULL,
PRIMARY KEY(User_ID,Stock_Symbol,Purchase_Time),
FOREIGN KEY(User_ID) REFERENCES Users(User_ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(Stock_Symbol) REFERENCES Stocks(Stock_Symbol)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE Holding_History (
User_ID CHAR(10) ,
Transaction_ID CHAR(12),
Purchase_time_stamp TIMESTAMP NOT NULL,
Sold_time_stamp TIMESTAMP NOT NULL,
Sold_Price DECIMAL(10,2) NOT NULL,
Bought_Price DECIMAL(10,2) NOT NULL,
Qty INT NOT NULL,
PRIMARY KEY (Transaction_ID),
FOREIGN KEY(User_ID) REFERENCES Users(User_ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(Transaction_ID) REFERENCES Wallet_Stock(Transaction_ID)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE Stocks (
Stock_Symbol VARCHAR(30) PRIMARY KEY,
Sname VARCHAR(60) UNIQUE NOT NULL,
Stype VARCHAR(20) ,
Highest DECIMAL(10,2),
Lowest DECIMAL(10,2),
Exchange VARCHAR(20) NOT NULL,
CIN CHAR(21),
FOREIGN KEY(CIN) REFERENCES Company(CIN)
ON UPDATE CASCADE
ON DELETE SET NULL
);
CREATE TABLE Stock_History (
Time_Stamp TIMESTAMP NOT NULL,
Stock_Symbol VARCHAR(30),
Inc_Dec DECIMAL(10,2) NOT NULL,
Price DECIMAL(10,2) NOT NULL,
Open_Price DECIMAL(10,2) NOT NULL,
Previous_Close DECIMAL(10,2) NOT NULL,
Volume VARCHAR(15) NOT NULL,
PRIMARY KEY(Time_Stamp,Stock_Symbol),
FOREIGN KEY(Stock_Symbol) REFERENCES Stocks(Stock_Symbol)
ON UPDATE CASCADE
);
CREATE TABLE Member_of (
Stock_Symbol VARCHAR(30),
Group_symbol VARCHAR(30),
PRIMARY KEY(Stock_Symbol,Group_Name),
FOREIGN KEY(Stock_Symbol) REFERENCES Stocks(Stock_Symbol)
ON UPDATE CASCADE,
FOREIGN KEY(Group_symbol) REFERENCES Stock_Group(Group_symbol)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE Stock_Group (
Group_Name VARCHAR(60),
Group_symbol VARCHAR(30) PRIMARY KEY,
Lowest DECIMAL(10,2) NOT NULL,
Highest DECIMAL(10,2) NOT NULL,
Stock_Exchange VARCHAR(10) NOT NULL
);
CREATE TABLE Stock_Group_History (
Time_Stamp TIMESTAMP NOT NULL,
Group_symbol VARCHAR(30) NOT NULL,
Inc_Dec DECIMAL(10,2) NOT NULL,
Price DECIMAL(10,2) NOT NULL,
Open_Price DECIMAL(10,2) NOT NULL,
Close_Price DECIMAL(10,2) NOT NULL,
PRIMARY KEY(Time_Stamp,Group_symbol),
FOREIGN KEY(Group_symbol) REFERENCES Stock_Group(Group_symbol)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE Company (
CIN CHAR(21) PRIMARY KEY,
Cname VARCHAR(50) NOT NULL,
CEO VARCHAR(50),
Market_Capital VARCHAR(30),
Revenue VARCHAR(30)
);
CREATE TABLE Sector(
Sector_Name VARCHAR(30),
CIN CHAR(21),
PRIMARY KEY(Sector_Name,CIN),
FOREIGN KEY(CIN) REFERENCES Company(CIN)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE Orders (
Order_ID CHAR(10) PRIMARY KEY,
Order_time TIMESTAMP NOT NULL,
User_ID CHAR(10) NOT NULL,
Stock_Symbol VARCHAR(30),
Trading_type VARCHAR(10) NOT NULL,
Price DECIMAL(10,2) NOT NULL,
Qty INT NOT NULL,
Status CHAR(1) NOT NULL,
Order_type VARCHAR(10) NOT NULL,
FOREIGN KEY(User_ID) REFERENCES Users(User_ID)
ON UPDATE CASCADE
ON DELETE CASCADE,
FOREIGN KEY(Stock_Symbol) REFERENCES Stocks(Stock_Symbol)
ON UPDATE CASCADE
);
CREATE TABLE News (
CIN CHAR(21),
Title TEXT,
Description TEXT,
PRIMARY KEY (CIN,Title),
FOREIGN KEY(CIN) REFERENCES Company(CIN)
ON UPDATE CASCADE
ON DELETE CASCADE
);
CREATE TABLE IPO (
IPO_Name VARCHAR(50),
Open_Date date,
CIN CHAR(21),
Issue_Price VARCHAR(20) NOT NULL,
Close_Date DATE NOT NULL,
Lot_Size INT NOT NULL,
Issue_Size VARCHAR(20),
Minimum_Invest DECIMAL(10,2) NOT NULL,
Listing_Date date,
PRIMARY KEY(IPO_Name),
FOREIGN KEY(CIN) REFERENCES Company(CIN)
ON UPDATE CASCADE
ON DELETE CASCADE
);