Cloud Stack Ninja

import sqlite3 from time import time

#Creation of connection

con=sqlite3.connect('hospitaldb')#creates a db named hospital

with con: #create cursor cur=con.cursor()

#creation of tables
cur.execute("CREATE TABLE IF NOT EXISTs patient_details(id int,first_name text,last_name text,age int,disease text)")

#to check the number of tables in database hospitaldb
cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
for row in rows:

#insert records in patient_details try: cur.execute("INSERT INTO patient_details VALUES (1,'ab','cd',45,'heart Attack')")

except: print("record exists")

Read more here:

Content Attribution

This content was originally published by Leafia Dias at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: