views:

53

answers:

2

HI all,

  Is there any way of create view if not exists in sql on mysql db or h2 db.
+3  A: 

The usual way is to overwrite a view using create or replace:

create or replace view YourView
as
select * from users
Andomar
+2  A: 

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.

Do you not understand how to make a link? This was copy/pasted from the [MySQL reference manual](http://dev.mysql.com/doc/refman/5.0/en/create-view.html). I'm finding way too many answers copy/pasted directly from other sites without any attempt at attribution at all.
Bill the Lizard