-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite.py
49 lines (25 loc) · 993 Bytes
/
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
47
48
49
import sqlite3
## Connect to Sqlite3 database
connection=sqlite3.connect("student.db")
# Create a cursor object to insert record or create table
cursor=connection.cursor()
#create the table
table__info="""
Create table STUDENT(NAME VARCHAR(25), CLASS VARCHAR(25), SECTION VARCHAR(25));
"""
print(table__info)
cursor.execute(table__info)
##Insert Some more Records into the table
cursor.execute("Insert Into STUDENT values('Rahul','Data Science','A')")
cursor.execute("Insert Into STUDENT values('Akshay','Science','D')")
cursor.execute("Insert Into STUDENT values('Pankaj','Gaming','B')")
cursor.execute("Insert Into STUDENT values('Darius','Devops','A')")
cursor.execute("Insert Into STUDENT values('Dipesh','Devops','A')")
##Display all the records from the table
print("The inserted records are :")
data=cursor.execute('''Select * from STUDENT''')
for row in data:
print(row)
## COmmit your changes to the database
connection.commit()
connection.close()