MySql Archive

MySQL, add a string in start of all column values

MySQL,  add a string  in start of all column values Recently I come  to know a very cool function in mysql that is CONCAT.   There  is a table in mysql database known as tbl_clients.  Structure of this table is as follows: tbl_clients id int(11) auto_increment, P.K client_name varchar(500) . . . . website varchar(500) there

Mysql – Regex Operator

In Mysql if we want to run a query that has condition like record should start with ‘D’ or ‘E’. Normally we use Like Operator. select * from tablename where name like 'D%' OR name like 'E%' But using REGEX in MySql we can get same result without using OR in query select * from

Mysql – disabling and enabling foreign key checks

Recently I was working on a project in which I have to truncate tables in database. But due to foreign key constraints MySQL was throwing errors. So the solution I found was to disable Foreign Key constraints temporarily delete all data and then again enable the foreign keys. Disable foreign key checks. SET FOREIGN_KEY_CHECKS=0; Enable

MySql – search and replace a string in a column

If we and to search some specific string inside our column data and replace it with other string then we can use replace query of MySql. Suppose table name is ‘users’ and we want to search city column with a value ‘London’ and replace it with ‘New York’ update users set city = replace(city, 'London',