I have the following SQL table called datatable
.
date source reading tday yday
---------------------------------------------
2021-05-27 x1 x x x
2021-05-27 x2 x x x
2021-05-27 x3 x x x
2021-05-28 x1 x x x
2021-05-28 x2 x x x
2021-05-28 x3 x x x
2021-05-31 x1 x x x
2021-05-31 x2 x x x
2021-05-31 x3 x x x
I want to update the date from 2021-05-31
to 2021-06-01
, I only have 1 database and I'm worried about messing up the data, how can I do it?
It should look like this
date source reading tday yday
----------------------------------------------
2021-05-27 x1 x x x
2021-05-27 x2 x x x
2021-05-27 x3 x x x
2021-05-28 x1 x x x
2021-05-28 x2 x x x
2021-05-28 x3 x x x
2021-06-01 x1 x x x
2021-06-01 x2 x x x
2021-06-01 x3 x x x
I think it would be something like
UPDATE date
FROM datatable
WHERE date = '2021-05-31' TO '2021-06-01';
or
UPDATE datatable
SET date = '2021-06-01'
WHERE date = '2201-05-31';
The date column is a date time format.
EDIT.
How can I add the data first, then delete the old one?
So like, copy the data from 2021-05-31 as 2021-06-01, (all the other columns would be columns from 2021-05-31's data except the date)
date source reading tday yday
---------------------------------------------
2021-05-27 x1 x x x
2021-05-27 x2 x x x
2021-05-27 x3 x x x
2021-05-28 x1 x x x
2021-05-28 x2 x x x
2021-05-28 x3 x x x
2021-05-31 x1 x x x
2021-05-31 x2 x x x
2021-05-31 x3 x x x
2021-06-01 x1 x x x
2021-06-01 x2 x x x
2021-06-01 x3 x x x
Then delete the rows where 2021-05-31, so I end up with
For this I'm guessing the query would be:
DELETE FROM datatable
WHERE date = '2021-05-31';
date source reading tday yday
--------------------------------------------
2021-05-27 x1 x x x
2021-05-27 x2 x x x
2021-05-27 x3 x x x
2021-05-28 x1 x x x
2021-05-28 x2 x x x
2021-05-28 x3 x x x
2021-06-01 x1 x x x
2021-06-01 x2 x x x
2021-06-01 x3 x x x