-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
40 lines (28 loc) · 958 Bytes
/
sql.py
File metadata and controls
40 lines (28 loc) · 958 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
31
32
33
34
35
36
37
38
39
40
import sqlite3
## Connect to sqllite
connection = sqlite3.connect("student.db")
# create a cursor object to insert record , create table , retrieve
cursor = connection.cursor()
# create the 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('kiran', 'SocialScience' , 'A' , 90)''')
cursor.execute('''Insert Into STUDENT values('Harsh', 'Hindi' , 'A' , 98)''')
cursor.execute('''Insert Into STUDENT values('Adi', 'Maths' , 'A' , 100)''')
cursor.execute('''Insert Into STUDENT values('Hina', 'Science' , 'A' , 85)''')
# Display all the record
print("The inserted records are")
data = cursor.execute('''Select * From STUDENT''')
for row in data:
print(row)
# Close the connection
connection.commit()
connection.close()