SQL vs Python
SQL
- to store data & initial processing
- for operations on large datasets (many rows & columns)
- for heavy duty tasks
- limited numbers of built-in functions
- often more efficient (python every time code executed, connects to database again)
Python
- for exploratory & further data analysis
- many built-in functions
Python connecting to database
Connecting Python & database - code
inport sqlite3
db = sqlite3.connect(“path…”)
Querying database with Python - code
db.execute(“SELECT … FROM …”).fetchone()
Adding a record to database with Python - code
db.execute(“INSERT INTO table(column) VALUES (“…”)”)
Return output - code
Parameters
Error Handling
SQL Injections: Danger
approaches of calculating most expensive product