EN
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 answer
1
points
Solution:
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