-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyDB_SQLite_2.py
More file actions
30 lines (22 loc) · 837 Bytes
/
PyDB_SQLite_2.py
File metadata and controls
30 lines (22 loc) · 837 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
28
29
30
# Program 2
import sqlite3
conc = sqlite3.connect("C:/Users/vasud/Desktop/Workstation/Py_Program/Database/MyDatabase_1.db")
crsr = conc.cursor()
crsr.execute("DROP TABLE MyDBTable;")
crsr.execute('''CREATE TABLE MyDBTable (
ID INTEGER,
Name VARCHAR(15),
City VARCHAR(10)
);''')
student_data = [("1","Vasudevan","03-01-2002"),
("2","Udhayakumar","15-10-2001"),
("3","Naveen","25-07-2002")]
for p in student_data:
format_str = """ INSERT INTO
MyDBTable(ID,Name,City)
Values("{vid}","{vname}","{vcity}"); """ # {} --> Space Holder
sql_command = format_str.format(vid = p[0],vname=p[1],vcity=p[2])
crsr.execute(sql_command)
conc.commit()
conc.close()
print("Record Added")