GowriHarikrishnan/Text2SQL_Basics
0
1import sqlite32 3#Connect to SQLite4connection = sqlite3.connect("retail.db")5 6#Creating a cursor to insert, retrieve and modify db records7cursor = connection.cursor()8 9#Creating the table10table_info = """11Create table RETAIL(PR_ID VARCHAR(25), PR_SUB_CAT VARCHAR(25), PR_CAT VARCHAR(25), DATE datetime, SALES INT);12"""13 14cursor.execute(table_info)15 16#Insert data into the table17 18cursor.execute('''Insert Into RETAIL values('PD001','Vegetables','FRESH','2024-03-26',56)''')19cursor.execute('''Insert Into RETAIL values('PD001','Vegetables','FRESH','2024-03-25',90)''')20cursor.execute('''Insert Into RETAIL values('PD001','Vegetables','FRESH','2024-03-24',05)''')21cursor.execute('''Insert Into RETAIL values('PD001','Vegetables','FRESH','2024-03-23',13)''')22cursor.execute('''Insert Into RETAIL values('PD001','Vegetables','FRESH','2024-03-22',40)''')23cursor.execute('''Insert Into RETAIL values('PD002','Vegetables','FRESH','2024-03-25',60)''')24cursor.execute('''Insert Into RETAIL values('PD002','Vegetables','FRESH','2024-03-24',19)''')25cursor.execute('''Insert Into RETAIL values('PD002','Vegetables','FRESH','2024-03-23',04)''')26cursor.execute('''Insert Into RETAIL values('PD002','Vegetables','FRESH','2024-03-22',21)''')27cursor.execute('''Insert Into RETAIL values('PD003','Vegetables','FRESH','2024-03-26',89)''')28 29#Display the data30print("The insereted records are:")31 32data = cursor.execute('''SELECT * FROM RETAIL;''')33 34for row in data:35 print(row)36 37#closing the connection38connection.commit()39connection.close()