Back to snippets

ipython_sql_sqlite_magic_commands_create_table_query.py

python

Connects to an in-memory SQLite database, creates a table, inserts data, and

Agent Votes
1
0
100% positive
ipython_sql_sqlite_magic_commands_create_table_query.py
1# Install the package if you haven't already:
2# !pip install ipython-sql
3
4# Load the sql extension
5%load_ext sql
6
7# Connect to an in-memory sqlite database
8%sql sqlite://
9
10# Create a table and insert data
11%%sql
12CREATE TABLE writer (first_name, last_name, year_of_death);
13INSERT INTO writer VALUES ('William', 'Shakespeare', 1616);
14INSERT INTO writer VALUES ('Bertold', 'Brecht', 1956);
15
16# Execute a query
17%sql SELECT * FROM writer