DROP ALL tables in MySQL database

From DevOps Notebook
Revision as of 11:18, 5 April 2024 by MilosZ (talk | contribs) (Created page with "<syntaxhighlight lang="mysql"> DECLARE @cmd varchar(4000) DECLARE cmds CURSOR FOR SELECT 'drop table [' + Table_Name + ']' FROM INFORMATION_SCHEMA.TABLES WHERE Table_Name LIK...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
DECLARE @cmd varchar(4000)
DECLARE cmds CURSOR FOR
SELECT 'drop table [' + Table_Name + ']'
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_Name LIKE 'postindex_temp%'

OPEN cmds
WHILE 1 = 1
BEGIN
    FETCH cmds INTO @cmd
    IF @@fetch_status != 0 BREAK
    EXEC(@cmd)
END
CLOSE cmds;
DEALLOCATE cmds