programing

create if not exists view?

goodsources 2023. 9. 8. 21:27
반응형

create if not exists view?

할 방법이 없을까요?create view if not existsMySQL 또는 H2 데이터베이스에서?

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.

일반적인 방법은 다음을 사용하여 보기를 덮어쓰는 것입니다.create or replace:

create or replace view YourView
as
select * from users

On H2 you can add IF NOT EXISTS before the view name you want to create. e.g.:

CREATE VIEW IF NOT EXISTS viewExampleName (column1, column2) 
AS ( 
    SELECT column1, column2
    FROM example_table 
); 

ReferenceURL : https://stackoverflow.com/questions/3316950/create-if-not-exists-view

반응형