PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

CREATE VIEW

劉䓄

CREATE VIEW -- 垔幬婔婻桄蓖商

臺濘

CREATE [ OR REPLACE ] [ TEMP | TEMPORARY ] VIEW name [ ( column_name [, ...] ) ]
    AS query

柟誄

CREATE VIEW 垔幬婔婻昖臵䔇蓖商㔗認婻蓖商婉滇䬷䊖婪垂鍙庻婘䔇幽婫婘臖蓖商懟渇赆嚘䫘䔇施唍鄘嚔誊臯婔渇 query

CREATE OR REPLACE VIEW 䌂嚚婉誺滇套悩婔婻劯劉䔇蓖商噾䂟庻婘闼幽儖敪扵垄㔗嘹埻脘䫘婔婻䫘潊䕩劯庖枕䔇桄昖臵敪扵婔婻蓖商(庖枕劉启昄扞䌂傋鄘䕩劯)㔗

套悩䂍庺庖婔婻昇嚟劉(懫套 CREATE VIEW myschema.myview ...)闼幽臖蓖商儖婘毺垔䔇昇嚟婺录傺劥彍儖婘嘷嬉昇嚟婺录傺㔗婘施蓖商庻婘庯婔婻䬹枪䔇昇嚟麯欔傖录傺婘施蓖商䔇施唍婉䫘䂍庺昇嚟劉㔗桄蓖商劉庖媙驔启劯婔昇嚟婺傂嘘噽垄蓖商㔕臘㔕废彖㔕䘵嚘䔇劉庖婉劯㔗

埗昄

TEMPORARYTEMP

套悩弄滯庖認婻床埖闼幽蓖商儌傖婘施蓖商䔇桹嚟录傺㔗婘施蓖商婘嘷嬉嚔臺䂷溘䔇施唍儖赆躻媘役鍴㔗嘷嬉嚔臺婺婘婘施蓖商庻婘䔇橘閘儖方濘䩋彄䯄橬䔇劯劉噿係鍴麂䫘昇嚟媞閄䔇劉庖嚘䫘垄傸㔗

套悩蓖商嚘䫘䔇傂嘘嘺䇔臘滇婘施䔇闼幽蓖商儖赆录傺婺婘施䔇(婉䞇滇劥弄滯庖 TEMPORARY)㔗

name

欔襕录傺䔇蓖商劉䓄(埇傖橬昇嚟媞閄)

column_name

婔婻埇锬䔇劉庖彖臘䫘嘩蓖商䔇庖枕劉㔗套悩澇橬䂍庺庖枕劉埡躻昖臵㔗

query

婔婻儖婺蓖商柊冕臯启彖䔇 SELECTVALUES 臺埖㔗

濘懟

䕞嬉蓖商滇埻臂䔇係䂘儖婉噕螩婘蓖商婪某噖㔕敘桄㔕役鍴昄扞㔗嘹埇傖锔誺婘蓖商婪录傺檪某噖京媘嘩麉喍婺劏噽垄臘啔劽锗淉嘩䔇蓇彍準垂䯄埇敘桄蓖商䔇昽悩㔗敘崔媇敇臥蓕 CREATE RULE

嘪䫘 DROP VIEW 臺埖役鍴蓖商㔗

臙濘懟蓖商庖枕䔇劉庖启䌂傋婉婔垔滇嘹傸橘橕䔇闼湙㔗懫套

CREATE VIEW vista AS SELECT 'Hello World';

婘婴婻桹麵冽俘俘庖枕劉䚺䩕滇 ?column? 幽婫庖枕䔇昄扞䌂傋䚺䩕滇 unknown 㔗套悩嘹愿蓖商䔇䂷悩滇婔婻庖严婾桺橸闼幽臙償婋麵認湙嘪䫘

CREATE VIEW vista AS SELECT text 'Hello World' AS hello;

凹蓖商嚘䫘䔇臘䔇螪閞䔇溄鍊䫌蓖商䔇欔橬蔙喿垔㔗婉誺婘蓖商麯脄䫘䔇庘昄嘷嘩傡傸䕘毖傯嘪䫘蓖商䔇昖臵麯脄䫘䩋写㔗啹溴蓖商䔇䫘潙媙釂橬嘪䫘蓖商脄䫘䔇欔橬庘昄䔇溄鍊㔗

冋床

录傺婔婻䫌欔橬塩嬓䫕嘌䂇潊䔇蓖商

CREATE VIEW comedies AS
    SELECT *
    FROM films
    WHERE kind = 'Comedy';

噚垹攓

SQL 湺庖婺 CREATE VIEW 弄滯庖婔底鍇媹䔇媘脘

CREATE VIEW name [ ( column_name [, ...] ) ]
    AS query
    [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]

垯昘䔇 SQL 变傴埇锬䔇床埖滇

CHECK OPTION

認婻锬釹䫘庯埇敘桄蓖商㔗欔橬凹蓖商䔇 INSERTUPDATE 鄘襕䂟誺蓖商垔幬溇傽䔇湇黯㔗幘儌滇臘桄昄扞庫臖埇傖锔誺蓖商䩋彄㔗套悩澇橬锔誺湇黯敘桄儖赆拐䂺㔗

LOCAL

凹認婻蓖商誕臯垯昘攓演昖

CASCADED

凹溴蓖商启傂嘘䕩噿蓖商誕臯垯昘攓演昖㔗婘斵澇橬弄滯 CASCADED 幘澇橬弄滯 LOCAL 施啺螆婺 CASCADED

CREATE OR REPLACE VIEW 滇 PostgreSQL 䔇欷匘㔗婘施蓖商䔇楗媕幘滇欷匘㔗

埽蓕

DROP VIEW

劯锔饡釕嬉誕
CREATE USER婪婔亓DEALLOCATE