-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql.py
34 lines (25 loc) · 933 Bytes
/
sql.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
import sqlite3
## Connect to Sqlite
connection=sqlite3.connect("student.db")
## Create a Cursor object to insert record,create table,retrieve
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 ('Ajai','Data Science','A',90)''')
cursor.execute('''Insert Into STUDENT values ('Joel','Mech','A',95)''')
cursor.execute('''Insert Into STUDENT values ('Ajith','Mech','B',80)''')
cursor.execute('''Insert Into STUDENT values ('Sajan','Diploma','C',45)''')
cursor.execute('''Insert Into STUDENT values ('Jony','English','D',34)''')
#Display all the records
print('The inserted records are')
data=cursor.execute('''select * from STUDENT''')
for row in data:
print(row)
#Close the connection
connection.commit()
connection.close()