Page 255 - PYTHON-12
P. 255
For example, UPDATE student
SET Marks = 90
WHERE Rollno = 8;
The above statement shall change the value of Marks field to 90 for the student whose roll number is 8.
(a) Updating multiple columns
Modifying the values in more than one column can be done by separating the columns
along with the new values using SET clause, separated by commas.
For example, UPDATE student
SET Marks = 70, DOB=‘1998-08-11’
WHERE Name=“Payal”;
The above statement shall change the values for both the fields Marks and DOB to 70 and
‘1998-08-11’ for the student whose name is Payal.
(b) Updating to NULL values
The values for the attributes in a relation can also be entered as NULL using UPDATE
command.
For example, UPDATE student
SET Marks = NULL
WHERE Rollno = 9;
The above statement shall change the value of the field Marks to 0 for the student whose
roll number is 9.
(c) Updating using an expression or formula
For example, UPDATE student
SET Marks = Marks + 10
WHERE (Rollno = 5 or Rollno =10);
The above statement shall increment the value of Marks by 10 for all the records with
Roll number 5 or 10.
9. Removing Data from a Table
The DELETE statement is used to delete rows from a table.
Syntax for DELETE Statement:
DELETE FROM <table_name> WHERE <condition>;
here <table_name> is the table whose records are to be deleted.
POINT TO REMEMBER
Relational Database and SQL
The WHERE clause in the SQL delete command is optional and it identifies the rows in the column that get
deleted. If you do not include the WHERE clause, all the rows in the table are deleted.
For example, DELETE FROM student WHERE Rollno = 10;
The above statement shall delete the record only for roll number 10.
To delete all the rows from the student table, the DELETE statement will be: DELETE FROM
student;
12.25