Top community members
All Questions Ask Question

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

MySQL drop view if exists

1 answers
3 points

How can I drop view only when this view exists in MySQL?
I want to check if the view exists because when it doesn't and I will drop it, then I will get error.

I know I can remove view without checking it's existence with this commnad:

DROP VIEW `users_view`;

But it won't protect me from getting error if this view already was removed earlier or never existed.

1 answers
1 points


DROP VIEW IF EXISTS `users_view`;

This SQL will check if the view exists and if it does, it will drop this view.

If we execute it when view doesn't exist, we will get only warrning.

I tested it on windows with HeidiSQL client. When I executed this mysql query I got Warrning: Note: Unknown VIEW: 'test.users_view'. I have all warnings enabled.

From MySQL documentation:

DROP VIEW IF EXISTS `view_name`;


0 comments Add comment

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more