Update Operation

The UPDATE-SET statement is used to update any column inside the table. The following SQL query is used to update a column.

snippet
>  update Employee set name = 'alex' where id = 110

Consider the following example.

Example

snippet
import mysql.connector

#Create the connection object 
myconn = mysql.connector.connect(host = "localhost", user = "root",passwd = "google",database = "PythonDB")

#creating the cursor object
cur = myconn.cursor()

try:
    #updating the name of the employee whose id is 110
    cur.execute("update Employee set name = 'alex' where id = 110")
    myconn.commit()
except:
    
    myconn.rollback()

myconn.close()
Update Operation

Delete Operation

The DELETE FROM statement is used to delete a specific record from the table. Here, we must impose a condition using WHERE clause otherwise all the records from the table will be removed.

The following SQL query is used to delete the employee detail whose id is 110 from the table.

snippet
>  delete from Employee where id = 110

Consider the following example.

Example

snippet
import mysql.connector

#Create the connection object 
myconn = mysql.connector.connect(host = "localhost", user = "root",passwd = "google",database = "PythonDB")

#creating the cursor object
cur = myconn.cursor()

try:
    #Deleting the employee details whose id is 110
    cur.execute("delete from Employee where id = 110")
    myconn.commit()
except:
    
    myconn.rollback()

myconn.close()
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +