In [56]:
import sqlite3
my_conn = sqlite3.connect('test2_db') # Change your database name here
print("Connected to database successfully")
r_set=my_conn.execute("CREATE TABLE IF NOT EXISTS dt_table ( \
  record_id varchar(4) NOT NULL, \
  date text NOT NULL, \
  `month-year` varchar(10) NOT NULL)") 
my_conn.commit() 
data=[('-15', '2020-09-03','Sep-2020' ),
('-14', '2020-09-02','Sep-2020' ),
('-13', '2020-09-01','Sep-2020' ),
('-12', '2020-08-31','Aug-2020' ),
('-11', '2020-08-30','Aug-2020' ),
('-10', '2020-08-29','Aug-2020' ),
('-9', '2020-08-28','Aug-2020' ),
('-8', '2020-08-27','Aug-2020' ),
('-7', '2020-08-26','Aug-2020' ),
('-6', '2020-08-25','Aug-2020' ),
('-5', '2020-08-24','Aug-2020' ),
('-4', '2020-08-23','Aug-2020' ),
('-3', '2020-08-22','Aug-2020' ),
('-2', '2020-08-21','Aug-2020' ),
('-1', '2020-08-20','Aug-2020' ),
('0', '2020-08-19','Aug-2020' ),
('1', '2020-08-18','Aug-2020' ),
('2', '2020-08-17','Aug-2020' ),
('3', '2020-08-16','Aug-2020' ),
('4', '2020-08-15','Aug-2020' ),
('5', '2020-08-14','Aug-2020' ),
('6', '2020-08-13','Aug-2020' ),
('7', '2020-08-12','Aug-2020' ),
('8', '2020-08-11','Aug-2020' ),
('9', '2020-08-10','Aug-2020' ),
('10', '2020-08-09','Aug-2020' ),
('11', '2020-08-08','Aug-2020' ),
('12', '2020-08-07','Aug-2020' ),
('13', '2020-08-06','Aug-2020' ),
('14', '2020-08-05','Aug-2020' ),
('15', '2020-08-04','Aug-2020' ),
('16', '2020-08-03','Aug-2020' ),
]
r_set=my_conn.executemany("INSERT INTO dt_table VALUES (?, ?,?)",data)
my_conn.commit()
Connected to database successfully
In [57]:
# Check table dt_table
r_set=my_conn.execute("SELECT * from dt_table");
for row in r_set:
    print(row)
('-15', '2020-09-03', 'Sep-2020')
('-14', '2020-09-02', 'Sep-2020')
('-13', '2020-09-01', 'Sep-2020')
('-12', '2020-08-31', 'Aug-2020')
('-11', '2020-08-30', 'Aug-2020')
('-10', '2020-08-29', 'Aug-2020')
('-9', '2020-08-28', 'Aug-2020')
('-8', '2020-08-27', 'Aug-2020')
('-7', '2020-08-26', 'Aug-2020')
('-6', '2020-08-25', 'Aug-2020')
('-5', '2020-08-24', 'Aug-2020')
('-4', '2020-08-23', 'Aug-2020')
('-3', '2020-08-22', 'Aug-2020')
('-2', '2020-08-21', 'Aug-2020')
('-1', '2020-08-20', 'Aug-2020')
('0', '2020-08-19', 'Aug-2020')
('1', '2020-08-18', 'Aug-2020')
('2', '2020-08-17', 'Aug-2020')
('3', '2020-08-16', 'Aug-2020')
('4', '2020-08-15', 'Aug-2020')
('5', '2020-08-14', 'Aug-2020')
('6', '2020-08-13', 'Aug-2020')
('7', '2020-08-12', 'Aug-2020')
('8', '2020-08-11', 'Aug-2020')
('9', '2020-08-10', 'Aug-2020')
('10', '2020-08-09', 'Aug-2020')
('11', '2020-08-08', 'Aug-2020')
('12', '2020-08-07', 'Aug-2020')
('13', '2020-08-06', 'Aug-2020')
('14', '2020-08-05', 'Aug-2020')
('15', '2020-08-04', 'Aug-2020')
('16', '2020-08-03', 'Aug-2020')
In [55]:
try:
  my_conn.execute('''DROP table dt_table;''')
  print("dt_table table deleted")
except sqlite3.Error as my_error:
  print("error: ",my_error)
my_conn.commit()
dt_table table deleted
In [ ]: