-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loan_Management_Database_sql_server.sql
115 lines (101 loc) · 3.17 KB
/
Loan_Management_Database_sql_server.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
CREATE TABLE [loan_ticket] (
[id] integer(10) PRIMARY KEY IDENTITY(1, 1),
[borrower_id] integer(10) NOT NULL,
[loan_type] varchar(50) NOT NULL,
[loan_amount] decimal(10,2) NOT NULL,
[loan_tenure_in_months] integer(10) NOT NULL,
[interest_rate] decimal(3,2) NOT NULL,
[start_date] datetime NOT NULL,
[end_date] datetime NOT NULL,
[status] varchar[50] NOT NULL DEFAULT 'Ongoing',
[remark] text,
[created_at] timestamp DEFAULT 'now()'
)
GO
CREATE TABLE [borrower] (
[id] integer(10) PRIMARY KEY IDENTITY(1, 1),
[first_name] varchar(50) NOT NULL,
[last_name] varchar(50) NOT NULL,
[mobile] integer(10) NOT NULL,
[alternate_mobile] integer(10) NOT NULL,
[state] varchar(50) NOT NULL,
[district] varchar(50) NOT NULL,
[pincode] integer(6) NOT NULL,
[address] varchar(250) NOT NULL,
[account_number] varchar(50) NOT NULL,
[ifsc_code] varchar(11) NOT NULL,
[bank_name] varchar(50) NOT NULL,
[branch_name] varchar(50) NOT NULL,
[created_at] timestamp DEFAULT 'now()'
)
GO
CREATE TABLE [emi] (
[id] integer(10) PRIMARY KEY IDENTITY(1, 1),
[loan_ticket_id] integer(10) NOT NULL,
[emi_no] integer(10) NOT NULL,
[emi_amount] decimal(10,2) NOT NULL,
[outstanding_amount] decimal(10,2) NOT NULL,
[start_date] datetime NOT NULL,
[end_date] datetime NOT NULL,
[payment_id] integer(10) NOT NULL,
[status] varchar(50) NOT NULL DEFAULT 'Pending',
[created_at] timestamp DEFAULT 'now()',
[remark] text,
[penalty_id] integer(10)
)
GO
CREATE TABLE [documents] (
[id] integer(10) PRIMARY KEY IDENTITY(1, 1),
[document_name] varchar(50) NOT NULL,
[dcoument_folder] varchar(50) NOT NULL,
[created_at] timestamp DEFAULT 'now()'
)
GO
CREATE TABLE [kyc] (
[id] integer(10) PRIMARY KEY IDENTITY(1, 1),
[status] varchar(50) NOT NULL DEFAULT 'Pending',
[borrower_id] integer(10) NOT NULL,
[aadhar_number] integer(12) UNIQUE,
[pan_number] varchar(10) UNIQUE,
[documents_id] integer[],
[completion_date] datetime,
[created_at] timestamp DEFAULT 'now()',
[remark] text
)
GO
CREATE TABLE [penalty] (
[id] integer(10) PRIMARY KEY IDENTITY(1, 1),
[status] varchar(50) DEFAULT 'Pending',
[emi_id] integer(10) NOT NULL,
[amount] decimal(11,2) NOT NULL,
[payment_id] integer(10) NOT NULL,
[due_date] datetime,
[remark] text
)
GO
CREATE TABLE [payments] (
[id] integer(10) PRIMARY KEY IDENTITY(1, 1),
[amount] decimal(10,2) NOT NULL,
[payment_mode] varchar(50) NOT NULL,
[emi_id] integer(10) NOT NULL,
[bank_reference_id] varchar(50) NOT NULL,
[payment_date] datetime,
[remark] text
)
GO
ALTER TABLE [loan_ticket] ADD FOREIGN KEY ([borrower_id]) REFERENCES [borrower] ([id])
GO
ALTER TABLE [emi] ADD FOREIGN KEY ([loan_ticket_id]) REFERENCES [loan_ticket] ([id])
GO
ALTER TABLE [kyc] ADD FOREIGN KEY ([documents_id]) REFERENCES [documents] ([id])
GO
ALTER TABLE [payments] ADD FOREIGN KEY ([emi_id]) REFERENCES [emi] ([id])
GO
ALTER TABLE [kyc] ADD FOREIGN KEY ([borrower_id]) REFERENCES [borrower] ([id])
GO
ALTER TABLE [penalty] ADD FOREIGN KEY ([emi_id]) REFERENCES [emi] ([id])
GO
ALTER TABLE [penalty] ADD FOREIGN KEY ([payment_id]) REFERENCES [payments] ([id])
GO
ALTER TABLE [emi] ADD FOREIGN KEY ([payment_id]) REFERENCES [payments] ([id])
GO