File size: 903 Bytes
70255b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sqlite3

# Connect to the database
conn = sqlite3.connect('example.db')

# Create a table
conn.execute('''CREATE TABLE users
             (id INT PRIMARY KEY NOT NULL,
             name TEXT NOT NULL,
             email TEXT NOT NULL);''')

# Insert data into the table
conn.execute("INSERT INTO users (id, name, email) VALUES (1, 'John Doe', 'john.doe@example.com')")
conn.execute("INSERT INTO users (id, name, email) VALUES (2, 'Jane Doe', 'jane.doe@example.com')")

# Read data from the table
cursor = conn.execute("SELECT id, name, email FROM users")
for row in cursor:
    print(f"ID = {row[0]}, NAME = {row[1]}, EMAIL = {row[2]}")

# Update data in the table
conn.execute("UPDATE users SET email = 'jane.doe@newexample.com' WHERE id = 2")

# Delete data from the table
conn.execute("DELETE FROM users WHERE id = 1")

# Commit the changes and close the connection
conn.commit()
conn.close()