CoolFace
Apppublic

ATTRAIN/Text_to_SQL_query

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
sql.py43 linesDownload Raw Back to root
1import sqlite32 3##connect to sqlite4connection= sqlite3.connect("student.db")5 6## create a cursor object to insert records, create table, retrive data7cursor= connection.cursor()8 9##create the table10table_info="""11Create table STUDENT(NAME VARCHAR(25),CLASS VARCHAR(25),12SECTION VARCHAR(25),MARKS INT);13 14"""15 16cursor.execute(table_info)17 18#insert records into database table19 20cursor.execute('''Insert Into STUDENT values('Krish','Data Science','A',90)''')21cursor.execute('''Insert Into STUDENT values('Sudhanshu','Data Science','B',100)''')22cursor.execute('''Insert Into STUDENT values('Darius','Data Science','A',86)''')23cursor.execute('''Insert Into STUDENT values('Vikash','DEVOPS','A',50)''')24cursor.execute('''Insert Into STUDENT values('Dipesh','DEVOPS','A',35)''')25 26#display all the records27print("the inserted records are")28 29data=cursor.execute('''select * from STUDENT''')30 31for row in data :32    print(row)33 34## close the connection35connection.commit()36connection.close()37 38 39 40 41 42 43