Is there any way to create view if not exists
in MySQL or H2 Database?
Here is another method, where you don't have to duplicate the contents of the view: IF (NOT EXISTS (SELECT 1 FROM sys. views WHERE name = 'data_VVV')) BEGIN EXECUTE('CREATE VIEW data_VVVV as SELECT 1 as t'); END; GO ALTER VIEW data_VVVV AS SELECT VCV. xxxx, VCV.
The basic syntax for creating a view in MySQL is as follows: CREATE VIEW [db_name.] view_name [(column_list)] AS select-statement; [db_name.] is the name of the database where your view will be created; if not specified, the view will be created in the current database.
can we create a view without base tables? No.
From section 12.1.12. CREATE VIEW Syntax of the MySQL 5.0 Reference Manual:
CREATE VIEW Syntax CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] [DEFINER = { user | CURRENT_USER }] [SQL SECURITY { DEFINER | INVOKER }] VIEW view_name [(column_list)] AS select_statement [WITH [CASCADED | LOCAL] CHECK OPTION]
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. If the view does exist, CREATE OR REPLACE VIEW is the same as ALTER VIEW.
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