Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

RDBMS - Structured Query Language (SQL) Examples

Bootstrap the Runtime Environment

Load SQLite

In order to work with SQLite in Pyodide, we will need to load the relevant package. Run the following code.

You should see the following output:

[object Object]

Connect to a DB and Create a Cursor

We will need to create our university student course enrollment database. The call to connect() will create a connection to the specified database and implicitly create it if the database doesn’t exist.

To execute SQL statements and run SQL queries, we need a database cursor. This cursor will be used in the following exercises.

Interactive Examples

CREATE the students Table

You should see the following output:

students

INSERT Records into the students Table

SELECT Records from the students Table

You should see the following output:

(2, 'Anna', 'Schmidt', 'Physics', 18)
(3, 'Bella', 'Cruz', 'Math', 19)
(1, 'Mike', 'Clymer', 'Computer Science', 20)
(4, 'Lee', 'Jacobs', 'Physics', 21)

You should see the following output:

4

You should see the following output:

2

UPDATE a Record in the students Table

You should see the following output:

(1, 'Mike', 'Clymer', 'Computer Science', 100)

DELETE a Record in the students Table

You should see the following output:

(3, 'Bella', 'Cruz', 'Math', 19)
(1, 'Mike', 'Clymer', 'Computer Science', 20)
(4, 'Lee', 'Jacobs', 'Physics', 21)