Relational databases are an essential part of backend development across industries including finance and AI. SQL (Structured Query Language) is a type of database that allows storing, querying, and manipulating data.
Relational databases such as PostgreSQL support complex queries, transactions, and routine administration processes. They are efficient in dealing with structured data and offer advanced querying options with SQL.
Python provides the sqlite3
module that can be used to interact with a SQLite database. SQLite is a self-contained, high-reliability, embedded, full-featured, public-domain SQL database engine.
Let's build a simple relational database with Python's sqlite3 module. In this demo, we'll create an example.db
SQLite database, create a stocks
table in it, and insert data into this table. Here's the Python script to do this.
xxxxxxxxxx
if __name__ == "__main__":
import sqlite3
conn = sqlite3.connect('example.db')
c = conn.cursor()
c.execute('''CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)''')
c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
conn.commit()
conn.close()