Create a SQLite database with Python

In this example we create a SQLite database and insert some sample data into it, we will use this database in later examples

import sqlite3 as lite
import sys
 
con = lite.connect('test.db')
 
with con:
 
    cur = con.cursor()    
    cur.execute("CREATE TABLE Jobs(Id INT, Name TEXT, Salary INT)")
    cur.execute("INSERT INTO Jobs VALUES(1,'Programmer',30000)")
    cur.execute("INSERT INTO Jobs VALUES(2,'Manager',76000)")
    cur.execute("INSERT INTO Jobs VALUES(3,'Leader',45000)")
    cur.execute("INSERT INTO Jobs VALUES(4,'Admin',10000)")
    cur.execute("INSERT INTO Jobs VALUES(5,'IT',20000)")
    cur.execute("INSERT INTO Jobs VALUES(6,'SysAdmin',25000)")
    cur.execute("INSERT INTO Jobs VALUES(7,'CEO',90000)")
    cur.execute("INSERT INTO Jobs VALUES(8,'TeamLeader',35000)")

Save the code above and run as normal, you wont see much but the db will be created

SHARE
Previous articleJava GPIO push button example
Next articlePython query SQlite database example