title: SQL query to delete all rows from tables where the table name contains a certain string
body: <p>I have a database with many tables, and the names of many of those tables contain the letters "PMO". I'd like to be able to delete all the rows from all of the tables whose names contain the string "PMO". So, delete from table "PMOThing" and "PMOOtherThing" but not from table "Thing" or "OtherThing", for example. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It's been suggested that there's a question that is a duplicate. It's close, but not quite. The question is how to drop tables whose names contain a certain string. I don't want to drop these tables; I want to delete all of the rows from them, but keep the tables. If someone knows how to modify the code below (from the suggested duplicate question) to do what I want, that'd be cool!</p>
  
  <pre><code>DECLARE @cmd varchar(4000)
  DECLARE cmds CURSOR FOR
  SELECT 'drop table [' + Table_Name + ']'
  FROM INFORMATION_SCHEMA.TABLES
  WHERE Table_Name LIKE 'prefix%'
  
  OPEN cmds
  WHILE 1 = 1
  BEGIN
      FETCH cmds INTO @cmd
      IF @@fetch_status != 0 BREAK
      EXEC(@cmd)
  END
  CLOSE cmds;
  DEALLOCATE cmds
  </code></pre>