I seem to find many tutorials on how to work with two table, but I can't seem to figure out how to create two tables. I am probably missing something very simple.
I want to create a table for my_data_1 and my_data_2. Here is my code:
import sqlite3
my_data_1 = [('a',1,'BUY'),('b',2,'SELL'),('c',3,'HOLD')]
my_data_2 = [('a',1,5),('d',6,6),('e',2,7)]
#I am using :memory: because I want to experiment
#with the database a lot
conn = sqlite3.connect(':memory:')
c = conn.cursor()
c.execute('''CREATE TABLE MY_TABLE_1
(stock TEXT, price REAL, recommendation TEXT )''' )
### Something is probably wrong with the following line
c.execute('''CREATE TABLE MY_TABLE_2
(stock TEXT, price REAL, volume REAL )''' )
for ele in my_data_1:
c.execute('''INSERT INTO MY_TABLE_1 VALUES(?,?,?)''',ele)
conn.commit()
c.execute('SELECT* FROM MY_TABLE_1')
for entry in c:
print entry
c.execute('SELECT* FROM MY_TABLE_2')
for entry in c:
print entry
My output is:
(u'a', 1.0, u'BUY')
(u'b', 2.0, u'SELL')
(u'c', 3.0, u'HOLD')
So I have not created MY_TABLE_2. How should I do this?
Thank You in Advance.