I have an sql table which has the following rows.
(4081, 3, '', 'contrapreneurship.jpg', 15.0000, '2007-07-09 05:16:35', '2007-07-15 12:41:03', NULL, 0.00, 1, 1, 0, 0),
(4082, 3, '', 'istandaccused.jpg', 12.9500, '2007-07-15 12:34:00', '2007-07-15 12:37:24', NULL, 0.00, 1, 1, 0, 0),
(4083, 3, '', 'excitingthesenses.jpg', 45.0000, '2007-07-22 14:00:47', '2007-07-22 14:01:24', NULL, 0.00, 1, 1, 0, 0),
(4232, 2, '', 'ambushindevilspass.jpg', 125.0000, '2008-07-11 11:00:19', '2008-07-11 11:50:36', NULL, 0.00, 0, 1, 0, 0),
Now the path of the images has changed. How do i update the field, that is update the filepath.
Should be something like this ‘/new/images/istandaccused.jpg’
I have several thousand rows like these. how do i procede on updating it?
This will do a bulk update on the table inserting
/new/images/before the originalImagePathvalue.I would strongly suggest that you encapsulate the whole statement within a
BEGIN TRAN, so your statement becomes:Then you can do a
SELECTto make sure numbers are correct, and then eitherCOMMITorROLLBACKthe transaction if there are any problems.Thinking about this a bit more, you should definitely add a
WHEREclause so you only add the path to those records where an actual image exists. There are 2WHEREclauses that I can think of and they are:And
The first will exclude all records where there is no image and the image field is null.
The second is a combination of the first, but with the added check to see if an empty string has been added to a record. There maybe a few more alternatives to this, but these two will get you started.