import sqlite3
conn = sqlite3.connect('example.db') # connectiong to database or creating new if table does
not exist
cursor = conn.cursor() # allows python to use sql commands
cursor.execute('''CREATE TABLE IF NOT EXISTS Fruits( #creating table
code TEXT PRIMARY KEY, # text data-type, primary key -constraint
name TEXT,
price FLOAT);
''')
conn.commit() # saves all changes made
fruit_list = [('1','blackberry', 300.00),('2','raspberry', 250.00), ('3','bananas', 150.00),
('4','strawberry', 200.00)] #list of tuples
cursor.executemany('INSERT INTO Fruits VALUES(?,?,?)', fruit_list) # inserting data into table
cursor.execute('SELECT * FROM Fruits')
show_all = cursor.fetchall()
for e in show_all:
print('code: {} | name: {} | price {}'.format(e[0],e[1],e[2]))
You can combine all your conditions in the WHERE
clause with the logical operator OR
in a single statement:
DELETE
FROM Fruits
WHERE name='blackberry' OR price='150.00'