C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Update OperationThe UPDATE-SET statement is used to update any column inside the table. The following SQL query is used to update a column. > update Employee set name = 'alex' where id = 110 Consider the following example. Exampleimport 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() Delete OperationThe 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. > delete from Employee where id = 110 Consider the following example. Exampleimport 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()
Next TopicJoin Operation
|