-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlite.py
46 lines (30 loc) · 1.13 KB
/
sqlite.py
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
import sqlite3
## Connection to sqlite
connection = sqlite3.connect("students.db")
## Cursor object creation for insertion of record and create table
cursor = connection.cursor()
## create a table
table_info = """
create table STUDENT(
NAME VARCHAR(25),
CLASS VARCHAR(25),
SECTION VARCHAR(25),
MARKS INT
)
"""
cursor.execute(table_info)
## Insert some more records
cursor.execute('''Insert into STUDENT values('Anubhav', 'Data Science', 'A', 90)''')
cursor.execute('''Insert into STUDENT values('John', 'Data Science', 'B', 100)''')
cursor.execute('''Insert into STUDENT values('Mukesh', 'Data Science', 'A', 86)''')
cursor.execute('''Insert into STUDENT values('Jacob', 'Data Science', 'A', 50)''')
cursor.execute('''Insert into STUDENT values('Dipesh', 'Data Science', 'A', 35)''')
## Display all the results
print("The inserted records are")
data = cursor.execute('''SELECT * FROM STUDENT''')
for row in data:
print(row)
## Commit the changes in databases
connection.commit()
connection.close()
## cd LangChain_Projects cd Search_with_SQLDB