In this topic, we described about the UPDATE DATE with detailed example.
UPDATE DATE statement is used to update the date and time values in existing table. All the data and time values should be specified in double quotes ("). Use WHERE clause, if trying to update the specific rows that satisfies the condition. If the WHERE clause ignored, then all rows in the table gets effected by the UPDATE statement.
UPDATE table_name SET column_name = "YYYY-MM-DD" | "YYYY-MM-DD HH:MM:SS" WHERE condition;
- table_name – Specifies the name of the table.
- column_name – Specifies the name of the column that should update.
- condition – Specifies the condition that used to filter the row to update.
Let us consider below table(s) as an example table(s) to frame the SQL query for getting the desired results.
Scenario – Update the single row date value.
Requirement – Update employee date_of_hire in employee_details table. The query was as follows –
UPDATE employee_details SET date_of_hire = '2019-07-05' WHERE emp_id = 003;
By executing above query, we can update the date_of_hire of one employee whose emp_id is 003. The row after update was as follows –
Scenario – Update the multiple rows date value.
Requirement – Update multiple employees date_of_hire values in employee_details table. The query was as follows –
UPDATE employee_details SET date_of_hire = '2019-07-05' WHERE dept_id = 1000;
By executing above query, we can update the date_of_hire of multiple employees whose dept_id is 1000. The rows after update was as follows –