You must do this by running the following query:
UPDATE city SET slugs=LOWER(REPLACE(city_name, " ", "-"))
In this case, we use REPLACE to replace all instances with "-" in the existing city_name column, and then pass the result of this to the LOWER function (to convert the data to lower case) before setting the slugs field with this value.
Depending on how you βclearβ your data, you can also TRIM data (to remove all leading or trailing spaces in the city_name field) before applying REPLACE as such:
UPDATE city SET slugs=LOWER(REPLACE(TRIM(city_name), " ", "-"))
By the way, if you did not use (My) SQL, I would recommend reading the String Functions manual page - the time you spend on it now will be more than paying off in the future.
source share