Breaking News

Python-SQLite CRUD Example – Create Read Update Delete

Python SQLite CRUD – Create Table, Insert, Update, Delete, Where Clause, Conditionals, limiting data.

n this video, I demonstrated how to create a SQLite database using Python and perform CRUD operations.

Git Repo: https://github.com/hydrogeologist/python-sqlite

create database and connection

import sqlite3
conn = sqlite3.connect(‘tutorialcustomer.db’)

create a table

cursor.execute(“””CREATE TABLE customers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT
)
“””
)

create a table

cursor.execute(“””CREATE TABLE customers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT
)
“””
)

Select data from a table

cursor.execute(“SELECT * from customers”)

Select data from a table

cursor.execute(“SELECT * from customers where last_name=”Basu”)
cursor.execute(“SELECT * from customers where email like (‘%gmail%’)”)

order data

cursor.execute(“””
SELECT * from customers where email like (‘%gmail%’)
ORDER BY first_name desc
“””)

conditionals

cursor.execute(“””
SELECT * from customers where email like (‘%gmail%’)
AND id = 5
ORDER BY first_name desc
“””)
for row in cursor.fetchall():
#print(row)
print(row[1] +” ” + row[2] + ” ” + row[3])

Update data into a table

cursor.execute(“””
UPDATE customers
SET first_name=”UpdatedAnkan”
WHERE id=1
“””
)

Delete data from a table

cursor.execute(“””
DELETE from customers
WHERE id=10
“””
)

 859 total views,  1 views today

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.