-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_Insert.py
More file actions
27 lines (24 loc) · 762 Bytes
/
3_Insert.py
File metadata and controls
27 lines (24 loc) · 762 Bytes
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
#Create connection between python and sql
import mysql.connector as myconn
mydb = myconn.connect(host = 'localhost',user = 'root',password = '',database = 'School')
dbcursor = mydb.cursor()
data = [
(2, 'Bob', 2022, 'No'),
(3, 'Charlie', 2023, 'Yes'),
(4, 'Diana', 2024, 'No'),
(5, 'Ethan', 2023, 'Yes')
]
data_1 = [
(6, 'Fiona', 2022, 'Yes'),
(7, 'George', 2023, 'No'),
(8, 'Hina', 2024, 'Yes'),
(9, 'Ivan', 2022, 'Yes'),
(10, 'Jaya', 2023, 'No'),
(11, 'Kunal', 2024, 'Yes'),
(12, 'Lina', 2023, 'No'),
(13, 'Mohit', 2022, 'Yes'),
(14, 'Nina', 2024, 'Yes'),
(15, 'Omkar', 2023, 'No')
]
dbcursor.executemany("INSERT INTO student (ID, Name, Year, Fees_Paid) VALUES (%s, %s, %s, %s)", data_1)
mydb.commit()