0

I have a table of around 3 million records in my database and I want to delete all words that have less than 3 characters.

Example:

Cheap food in Spain
Because of my database

I want to delete "in", "of", "my", etc....

Expected result:

Cheap food Spain
Because database

Please help

Thanks!

urkeee
  • 19
  • 1
  • 4
  • So `Cheap food in Spain` is in _one_ column? – PerlDuck May 05 '16 at 13:50
  • I think you want something like `$col =~ /\b\S{1,3}\b\s?//g;` (that's Perl syntax to replace every 1-3 character word in a variable with nothing (i.e. delete it)). Unfortunately there's no REGEX REPLACE in MySQL, accoding to [this answer](http://stackoverflow.com/a/986870/5830574). – PerlDuck May 05 '16 at 13:59
  • 1
    You might try a search on MySQL replace with wildcards. There are several workarounds for the issue Perl Dog notes. – BRM May 05 '16 at 14:08
  • Cheap food in Spain, Because of my database, ... values in same column – urkeee May 05 '16 at 14:21
  • @urkeee I edited your Q. If I misunderstood it, feel free to reject or update my edit. – PerlDuck May 05 '16 at 14:29

2 Answers2

0

It might not be very efficient, but you could try the following:

delete from [Table] where [Column] like '% __ %' or [Column] like '% _ %'

This would drop your rows where you have 1 or 2 character words surrounded with spaces; you could tailor this to cope with full stops etc.

James
  • 1,028
  • 9
  • 20
0

You need to use cursor for this requirement, first take all the tables from database. and get all the column and it's type.

Please see below link for more information.

https://www.mssqltips.com/sqlservertip/1555/sql-server-find-and-replace-values-in-all-tables-and-all-text-columns/