-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite.py
More file actions
33 lines (23 loc) · 841 Bytes
/
Copy pathsqlite.py
File metadata and controls
33 lines (23 loc) · 841 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
import sqlite3
conn = sqlite3.connect('my_database.db')
cursor = conn.cursor()
tabel_info = """
CREATE TABLE IF NOT EXISTS student(
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
age INTEGER,
gender TEXT
)
"""
cursor.execute(tabel_info)
## Insert data into the table
cursor.execute("INSERT INTO student (name,age,gender) VALUES ('John',20,'Male')")
cursor.execute("INSERT INTO student (name,age,gender) VALUES ('Jane',21,'Female')")
cursor.execute("INSERT INTO student (name,age,gender) VALUES ('Jim',22,'Male')")
cursor.execute("INSERT INTO student (name,age,gender) VALUES ('Jill',23,'Female')")
## Display all data from the table
print("Displaying all data from the table")
for row in cursor.execute("SELECT * FROM student"):
print(row)
conn.commit()
conn.close()