Create a table

EasySQLite Programs · 1 of 20

Write a Python program to create a SQLite table and list the tables in the database.

Advertisement
Output
[('students',)]

Approach

  1. CREATE TABLE, then query sqlite_master.

Solution

Python
import sqlite3 conn = sqlite3.connect(":memory:")conn.execute("CREATE TABLE students (id INTEGER PRIMARY KEY, name TEXT NOT NULL, marks INTEGER)")print(conn.execute("SELECT name FROM sqlite_master WHERE type = 'table'").fetchall())
Output
[('students',)]

Line by line

Line 3

:memory: creates a temporary database that disappears when the program ends.

Learn the concept

New to this topic? Read the lesson, then come back.

More sqlite programs

← All 20 SQLite Programs

Leave a Comment