Team Ai
Apppublic

Kiash/texttoSQLgenerativeAI

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
sql.py40 linesDownload Raw Back to root
1import sqlite3 2 3#connect to sql db4connection=sqlite3.connect("student.db")5 6#create a cursor to create and instert data7cursor=connection.cursor()8 9#create a table with cursor fuction10table_info="""11Create table STUDENT(12    NAME VARCHAR(25),13    CLASS VARCHAR(25),14    SECTION VARCHAR(25),15    MARKS  INT16    );17"""18cursor.execute(table_info)19 20#instert record now21cursor.execute("""insert into STUDENT values('Samuel kiando','Data Science', 'A',90)""")22cursor.execute("""insert into STUDENT values('finix Muthii','C#', 'B',100)""")23cursor.execute("""insert into STUDENT values('Hellen Wamabui','Data Analyst', 'A-',50)""")24cursor.execute("""insert into STUDENT values('John Doe','Data mining', 'A',35)""")25cursor.execute("""insert into STUDENT values('JAne Doe','web dev', 'A',50)""")26cursor.execute("""insert into STUDENT values('Alice Doe','Data Science', 'A',90)""")27cursor.execute("""insert into STUDENT values('Hansen Doe','Data Science', 'A',89)""")28cursor.execute("""insert into STUDENT values('krish Doe','Data Science', 'B+',45)""")29 30 31#display the records 32print("The inserted records are")33data=cursor.execute(""" select * from STUDENT """)34for row in data:35    print(row)36    37# Commit the transactions38connection.commit()39connection.close()40