-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinsertValues.js
299 lines (266 loc) · 7.12 KB
/
insertValues.js
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
const mysql = require('mysql2');
const insertValues = () => {
// Create a connection to the MySQL database
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'sunil', // Modify to mYSQL paswiord
database: 'dbmsproj' // Create a database called iris in ur mysql
})
// Connect to the database
connection.connect((err) => {
if (err) {
console.error('Error connecting to database: ', err);
return;
}
console.log('Connected to database');
});
// Add values to the Student table
const Student = [
{
Reg_no: 123456,
Password: 'password123',
Name: 'John Doe',
Email: '[email protected]',
CGPA: 3.8,
Credits_Obtained: 120,
Fee_Paid: true,
Semester: 5,
Department_id: 1 // Assuming the department_id for the student
},
{
Reg_no: 234567,
Password: 'student234',
Name: 'Jane Smith',
Email: '[email protected]',
CGPA: 3.5,
Credits_Obtained: 110,
Fee_Paid: true,
Semester: 4,
Department_id: 2
},
// Add 3 more tuples with similar structure
];
// Loop through each student value and insert into the Student table
Student.forEach((value) => {
connection.query('INSERT INTO Student SET ? ', value, (err, result) => {
if (err) {
console.error('Error adding values to Student table: ', err);
return;
}
console.log('Values added to Student table');
});
});
// Similarly, add 3 more tuples to the Student table
// Add values to the Results table
const Results = [
{
Course_id: 1,
Student_Reg_no: 123456,
Score_obtained: 90.5
},
{
Course_id: 2,
Student_Reg_no: 234567,
Score_obtained: 85.0
},
// Add 3 more tuples with similar structure
];
// Loop through each result value and insert into the Results table
Results.forEach((value) => {
connection.query('INSERT INTO Results SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Results table: ', err);
return;
}
console.log('Values added to Results table');
});
});
// Similarly, add 3 more tuples to the Results table
// Add values to the Course_Info table
const CourseInfo = [
{
Course_id: 1,
Course_name: 'Introduction to Computer Science',
Credits: 3
},
{
Course_id: 2,
Course_name: 'Data Structures',
Credits: 4
},
// Add 3 more tuples with similar structure
];
// Loop through each course info value and insert into the Course_Info table
CourseInfo.forEach((value) => {
connection.query('INSERT INTO Course_info SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Course_info table: ', err);
return;
}
console.log('Values added to Course_Info table');
});
});
// Similarly, add 3 more tuples to the Course_Info table
// Add values to the Fee_transaction table
const feeTransaction = [
{
Reg_no: 123456,
Amount_paid: 500,
Semester: 5
},
{
Reg_no: 234567,
Amount_paid: 600,
Semester: 4
},
// Add 3 more tuples with similar structure
];
// Loop through each fee transaction value and insert into the Fee_transaction table
feeTransaction.forEach((value) => {
connection.query('INSERT INTO Fee_transaction SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Fee_transaction table: ', err);
return;
}
console.log('Values added to Fee_transaction table');
});
});
// Similarly, add 3 more tuples to the Fee_transaction table
// Add values to the Department table
const department = [
{
Department_id: 1,
Department_name: 'Computer Science'
},
{
Department_id: 2,
Department_name: 'Electrical Engineering'
},
// Add 3 more tuples with similar structure
];
// Loop through each department value and insert into the Department table
department.forEach((value) => {
connection.query('INSERT INTO Department SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Department table: ', err);
return;
}
console.log('Values added to Department table');
});
});
// Similarly, add 3 more tuples to the Department table
// Add values to the Professor table
const professor = [
{
Professor_id: 1,
Department_id: 1,
Name: 'Dr. Jane Smith',
Course_id: 1
},
{
Professor_id: 2,
Department_id: 2,
Name: 'Prof. John Doe',
Course_id: 2
},
// Add 3 more tuples with similar structure
];
// Loop through each professor value and insert into the Professor table
professor.forEach((value) => {
connection.query('INSERT INTO Professor SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Professor table: ', err);
return;
}
console.log('Values added to Professor table');
});
});
// Similarly, add 3 more tuples to the Professor table
// Add values to the Alumni table
const alumni = [
{
Reg_no: 654321,
Dept: 1,
Company_id: 1001,
Name: "John Marire"
},
{
Reg_no: 765432,
Dept: 2,
Company_id: 1002,
Name: "Ram Lal"
},
// Add 3 more tuples with similar structure
];
// Loop through each alumni value and insert into the Alumni table
alumni.forEach((value) => {
connection.query('INSERT INTO Alumni SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Alumni table: ', err);
return;
}
console.log('Values added to Alumni table');
});
});
// Similarly, add 3 more tuples to the Alumni table
// Add values to the Alumni Alerts/Messages table
const alumniMessages = [
{
Reg_no: 654321,
Message: 'Congratulations on your graduation!'
},
{
Reg_no: 765432,
Message: 'Best wishes for your future endeavors!'
},
// Add 3 more tuples with similar structure
];
// Loop through each alumni message value and insert into the Alumni Alerts/Messages table
alumniMessages.forEach((value) => {
connection.query('INSERT INTO Alumni_Message SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Alumni Alerts/Messages table: ', err);
return;
}
console.log('Values added to Alumni Alerts/Messages table');
});
});
// Similarly, add 3 more tuples to the Alumni Alerts/Messages table
// Add values to the Companies table
const companies = [
{
Company_id: 1001,
Dept_id: 1,
Salary_offered: 60000,
Company_name: 'Tech Solutions Inc.'
},
{
Company_id: 1002,
Dept_id: 2,
Salary_offered: 65000,
Company_name: 'Innovate Corp.'
},
// Add 3 more tuples with similar structure
];
// Loop through each company value and insert into the Companies table
companies.forEach((value) => {
connection.query('INSERT INTO Companies SET ?', value, (err, result) => {
if (err) {
console.error('Error adding values to Companies table: ', err);
return;
}
console.log('Values added to Companies table');
});
});
// Similarly, add 3 more tuples to the Companies table
// Close the connection after all operations
connection.end((err) => {
if (err) {
console.error('Error closing database connection: ', err);
return;
}
console.log('Connection closed');
});
}
module.exports = insertValues;