Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8516595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:28:22+00:00 2026-06-11T05:28:22+00:00

My database had lots of views and it was impossible to drop them one

  • 0

My database had lots of views and it was impossible to drop them one by one.

I would like to just drop them all because the database doesn’t refresh structure changes of the tables in the view that select from them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:28:23+00:00Added an answer on June 11, 2026 at 5:28 am

    After searching on the web, I found a shell script to drop all tables here: http://www.cyberciti.biz/faq/how-do-i-empty-mysql-database/

    Then, I changed that script to drop all views of the database.
    This is the final result:

    #!/bin/bash
    PREFIX=""
    SUFFIX=""
    HOST="localhost"
    PORT="3306"
    
    while getopts p:s:h:P: OPCAO; do
        case "${OPCAO}" in
          p) PREFIX="${OPTARG}" ;;
          s) SUFFIX="${OPTARG}" ;;
          h) HOST="${OPTARG}" ;;
          P) PORT="${OPTARG}" ;;
        esac
    done
    
    shift $((OPTIND-1))
    
    MUSER="$1"
    MPASS="$2"
    MDB="$3"
    
    # Detect paths
    MYSQL=$(which mysql)
    AWK=$(which awk)
    GREP=$(which grep)
    
    if [ $# -eq 0 ]
    then
        echo "Usage: $0 [-h Host] [-P Port] [-p Prefix-View-Name] [-s Suffix-View-Name] {MySQL-User-Name} {MySQL-User-Password} {MySQL-Database-Name}"
        echo "Drops all views from a MySQL"
        exit 1
    fi
    
    TABLES=$($MYSQL -h $HOST -P $PORT -u $MUSER -p$MPASS $MDB -e "SELECT table_name FROM information_schema.views WHERE table_schema = '$MDB' AND table_name LIKE '$PREFIX%$SUFFIX';" | $AWK '{ print $1}')
    
    for t in $TABLES
    do
        echo "Deleting $t view from $MDB database..."
        $MYSQL -h $HOST -P $PORT -u $MUSER -p$MPASS $MDB -e "drop view $t"
    done
    

    This solution will work just for who uses Unix-like systems.

    To call the script, I used:

    ./script.sh [-h host] [-P port] [-p prefixViewName] [-s suffixViewName] username password databaseName
    

    EDIT: I improved the script to accept option parameters, like the host, port and also a prefix and a suffix to filter what views will be dropped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All text field values in my database had been converted to upper case. I
I had more database and I tried to make backup for them but they
My Database was quite large with lots of test data in tables like watchdog,
Evening all, I just had a quick question about SQL average queries. I have
I had a database field which stores passwords like this: TeacherPassword j.lu01 pesci02 cricket01
If I had two database tables like this: +-----------------+ | dog | +-----------------+ |
I have these profiles saved in a database with lots of random information like
I have a database that had 15 years of cruft stuffed into it by
I have a live database that had some data deleted from it and I
i had sideshow ajax and i want it get images form database i used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.