I wanted to copy a column's data into a new column in my MySQL database or rather say I wanted to create a new column and copy data from an already existing column in same table.
If you too want to do the same just issue below commands either in MySQL console or SQL tab in phpmyadmin:
ALTER TABLE `table_name` ADD `new_column` varchar(700);
UPDATE `table_name` SET `new_column` = `old_column`;
First command creates the new column. Change the "varchar(700)" to whatever you want.
Second command copies the data from old column to new column.
Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts
Monday, September 9, 2019
Saturday, November 29, 2014
How to replace a character in MySQL table
Use this command in phpMyAdmin or in MySQL console:
update tablename set column_name = replace(column_name, 'character_to_be_replaced', 'characer_to_replaced_with');
For example:
I wanted to replace '&' with 'and' in table named 'tags' and column name 'tag' because that interfered with the URL.
I used following command
update tags set tag = replace(tag, '&', 'and');
I hope this help
update tablename set column_name = replace(column_name, 'character_to_be_replaced', 'characer_to_replaced_with');
For example:
I wanted to replace '&' with 'and' in table named 'tags' and column name 'tag' because that interfered with the URL.
I used following command
update tags set tag = replace(tag, '&', 'and');
I hope this help
Subscribe to:
Posts (Atom)