-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathUpdateSpecificColumn.py
More file actions
42 lines (31 loc) · 998 Bytes
/
UpdateSpecificColumn.py
File metadata and controls
42 lines (31 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# importing sqlite3 module
import sqlite3
# create connection by using object
# to connect with gfg database
connection = sqlite3.connect('gfg.db')
# insert query to insert student details
# in the above table
connection.execute(
"INSERT INTO STUDENTS VALUES (5, 'mohan pavan', 22, 'ponnur' )")
connection.execute(
"INSERT INTO STUDENTS VALUES (6, 'sudheer', 28, 'chebrolu' )")
connection.execute(
"INSERT INTO STUDENTS VALUES (7, 'mohan', 22, 'tenali' )")
# creating cursor object to display all
# the data in the table
cursor = connection.execute("SELECT * from STUDENTS")
# display data
print('\nOriginal Table:')
for row in cursor:
print(row)
# update query to update ADDRESS
connection.execute("UPDATE STUDENTS set ADDRESS = 'naga' where SAGE = 22")
# save the changes
connection.commit()
# creating cursor object to display
# all the data in the table
cursor = connection.execute("SELECT * from STUDENTS")
# display data
print('\nUpdated Table:')
for row in cursor:
print(row)