CoolFace
Apppublic

Akashr18/SQL-Query-Retrieval-App

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
sql.py35 linesDownload Raw Back to root
1import sqlite3 #By default come along with python setup2 3#Connection to Sqlite database4connection = sqlite3.connect('student.db')5 6#Creating cursor object7cursor = connection.cursor()8 9#Creating a table10table = """11    CREATE TABLE STUDENT(NAME VARCHAR(255), CLASS VARCHAR(255), SECTION VARCHAR(255), MARKS INT);12"""13cursor.execute(table)14 15#Insering records16cursor.execute("""INSERT INTO STUDENT VALUES('Poorna', 'Data Science', 'A', 82)""")17cursor.execute("""INSERT INTO STUDENT VALUES('Rishi', 'MLOPS', 'A', 72)""")18cursor.execute("""INSERT INTO STUDENT VALUES('Akash', 'Data Science', 'B', 97)""")19cursor.execute("""INSERT INTO STUDENT VALUES('Barat', 'Data Science', 'B', 99)""")20cursor.execute("""INSERT INTO STUDENT VALUES('Prabhu', 'MLOPS', 'C', 95)""")21cursor.execute("""INSERT INTO STUDENT VALUES('Vishnu', 'Data Science', 'C', 92)""")22cursor.execute("""INSERT INTO STUDENT VALUES('Sudhan', 'Data Science', 'D', 98)""")23cursor.execute("""INSERT INTO STUDENT VALUES('Kamal', 'MLOPS', 'D', 96)""")24print("Data inserted successfully")25data = cursor.execute(""" SELECT * FROM STUDENT """)26 27for row in data:28    print(row)29 30# Commit your changes in the database     31connection.commit() 32  33# Closing the connection 34connection.close()35