How do I create a view only if it doesn't exist. If it does exist, I want to drop the view and redefine it. I also want no warnings or errors.
The CREATE VIEW statement creates a new view, or replaces an existing one if the OR REPLACE clause is given. This statement was added in MySQL 5.0. 1. If the view does not exist, CREATE OR REPLACE VIEW is the same as CREATE VIEW.
The IF NOT EXISTS is optional. It allows you to check if the table that you create already exists in the database. If this is the case, MySQL will ignore the whole statement and will not create any new table. Second, you specify a list of columns of the table in the column_list section, columns are separated by commas.
The “CREATE TABLE if not exists” statement is very useful in creating a table because it will not create the table if the table of the same name already exists in the database.
MySQL doesn't support WITH READ ONLY for CREATE VIEW . The line DEFINER = CURRENT_USER is not needed if you use the limited user to create the view. Or you can use an admin user to create the view and in this case the line DEFINER = must contain the name of the user that will own the view.
You're going to kick yourself:
CREATE OR REPLACE VIEW ...
Details here. ;-)
CREATE OR REPLACE VIEW <view name>
AS
<your select expression goes here>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With