PY
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
import sqlite3
# PLEASE LIKE AND COMMENT IF YOU FIND THIS CODE USEFUL
# Use a TRY/EXCEPT block for error handling
try:
# Connect to the database
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
# Create table if it doesn't exist
query_create_table = '''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
name TEXT,
age INTEGER)
'''
cursor.execute(query_create_table)
# Insert data into the table
query_inserts = '''
INSERT INTO users (name, age) VALUES
('John', 15),
('Deb', 12),
('Grace', 17), \
('Jerry', 21), \
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run