In [1]:
import sqlite3
In [3]:
import sqlite3
conn = sqlite3.connect('JNV.db')
print ("Opened database successfully");
In [7]:
import sqlite3
conn = sqlite3.connect('JNV.db')
print ("Opened database successfully")
conn.execute('''CREATE TABLE JNVS
(SNO INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL);''')
print ("Table created successfully")
conn.close()
In [10]:
import sqlite3
conn = sqlite3.connect('JNV.db')
print ("Opened database successfully")
conn.execute("INSERT INTO JNVS (SNO,NAME,AGE,ADDRESS,SALARY) \
VALUES (1, 'rakesh', 32, 'California', 20000.00 )");
conn.execute("INSERT INTO JNVS (SNO,NAME,AGE,ADDRESS,SALARY) \
VALUES (2, 'Ajay', 25, 'Texas', 15000.00 )");
conn.execute("INSERT INTO JNVS (SNO,NAME,AGE,ADDRESS,SALARY) \
VALUES (3, 'verma ji', 23, 'Norway', 20000.00 )");
conn.execute("INSERT INTO JNVS (SNO,NAME,AGE,ADDRESS,SALARY) \
VALUES (4, 'ajit sngh', 25, 'Rich-Mond ', 65000.00 )");
conn.commit()
print ("Records created successfully")
conn.close()
In [15]:
import sqlite3
conn = sqlite3.connect('JNV.db')
print ("Opened database successfully");
cursor = conn.execute("SELECT sno, name, address, salary from JNVS")
for row in cursor:
print ("ID = ", row[0])
print ("NAME = ", row[1])
print ("ADDRESS = ", row[2])
print ("SALARY = ", row[3], "\n")
print ("Operation done successfully")
conn.close()
In [21]:
import sqlite3
conn = sqlite3.connect('JNV.db')
print ("Opened database successfully");
conn.execute("UPDATE JNVS set SALARY = 25000.00 where sno = 1")
conn.commit()
print ("Total number of rows updated :", conn.total_changes)
cursor = conn.execute("SELECT sno, name, address, salary from JNVS")
for row in cursor:
print ("sno = ", row[0])
print ("NAME = ", row[1])
print ("ADDRESS = ", row[2])
print ("SALARY = ", row[3], "\n")
print ("Operation done successfully")
conn.close()
In [22]:
import sqlite3
conn = sqlite3.connect('JNV.db')
print ("Opened database successfully");
conn.execute("DELETE FROM JNVS WHERE SNO=1")
conn.commit()
print ("Total number of rows updated :", conn.total_changes)
cursor = conn.execute("SELECT sno, name, address, salary from JNVS")
for row in cursor:
print ("sno = ", row[0])
print ("NAME = ", row[1])
print ("ADDRESS = ", row[2])
print ("SALARY = ", row[3], "\n")
print ("Operation done successfully")
conn.close()
In [ ]:
No comments:
Post a Comment