Skip to content

Instantly share code, notes, and snippets.

@antyblin
Last active March 18, 2016 00:00
Show Gist options
  • Save antyblin/8aa7532e6ed3ede8670a to your computer and use it in GitHub Desktop.
Save antyblin/8aa7532e6ed3ede8670a to your computer and use it in GitHub Desktop.
MySQL Drop all views for the table
/* DROP ALL VIEWS */
/* Taken from http://stackoverflow.com/a/22876345 */
SET @views = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @views
FROM information_schema.views
WHERE table_schema = @database_name; -- Your DB name here
SET @views = IFNULL(CONCAT('DROP VIEW ', @views), 'SELECT "No Views"');
PREPARE stmt FROM @views;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment