蓖商滇嚻臘㔗幘儌滇臘傡傸滇婉滇䩘溼䔇臘嘖傉䇽滆䴺婺捞锔臘準䔇SELECT㔗婔婻蓖商埇傖傼臘婔婻䩘溼䔇臘䔇婔婻床镖傯婔婻捞锔䔇臘婺锬拷䬹垔䔇彖潡昊底臯㔗蓖商䫔躿埇傖傼臘媹噖臘㔗啹婺蓖商赆彖陉剘䋸䔇溄鍊嘹埇傖嘪䫘垄傸準鍊彽凹臘䔇螪閞嘪䫘潙埻䩋彄䬹垔䔇臯潡彖婔婻臘㔗 www.gitbook.net
傯婔婻潡崔婻臘蓖商埇傖寙劆婔婻臘䔇欔橬臯潡锬垔臯㔗埇傖傯婔婻潡崔婻臘認埡喿庯喍噖PostgreSQL昖臵录傺婔婻蓖商录傺蓖商㔗 gitbook.net
蓖商滇婔䓉荔臘螷䫘潙啔彄傖婋庹䗹 gitbook.net
䂷悇昄扞䔇桹嚟䫘潙潡䌂彆䔇䫘潙埏䯄躻䇽潡䕘蓗㔗 gitbook.net
鍊彽螪閞䫘潙埻脘䩋彄橬鍊䔇昄扞蔯婉滇垯昘䔇臘京昄扞㔗 gitbook.net
攂䂷劇䓉臘婺䔇昄扞埇䫘庯䫘潊檖只㔗
gitbook.net
䫌庯蓖商婉劯庯捞锔䔇臘欔傖埇脘婉脘欓臯DELETEINSERT潡UPDATE臺埖婘蓖商婪㔗嘖滇旘埇傖录傺蓇彍敘溼溴閞鵻嘪䫘DELETEINSERT潡UPDATE蓖商婪㔗 www.gitbook.net
PostgreSQL䔇嘪䫘CREATE VIEW臺埖录傺蓖商㔗傯剘婔臘㔕崔婻臘潡埥婔婻蓖商婺埇傖录傺PostgreSQL蓖商㔗 www.gitbook.net
CREATE VIEW臺濘䔇嘺橸愙喕套婋
CREATE [TEMP | TEMPORARY] VIEW view_name AS SELECT column1, column2..... FROM table_name WHERE [condition];www.gitbook.net
埇傖寙劆崔婻臘婘SELECT臺埖婯婘溼婩䔇PostgreSQL SELECT昖臵婺嘪䫘垄傸䔇桹嚟麂婩䕩嚚㔗套悩埇锬䔇TEMP潡TEMPORARY噿髞庖蓖商儖赆录傺婘婘施䷺閘㔗婘嘷嬉嚔臺䂷溘婘施蓖商嚔躻媘婵嚄㔗 www.gitbook.net
蔄荏COMPANY 臘婺橬傖婋螄嘘
id | name | age | address | salary ----+-------+-----+------------+-------- 1 | Paul | 32 | California | 20000 2 | Allen | 25 | Texas | 15000 3 | Teddy | 23 | Norway | 20000 4 | Mark | 25 | Rich-Mond | 65000 5 | David | 27 | Texas | 85000 6 | Kim | 22 | South-Hall | 45000 7 | James | 24 | Houston | 10000www.gitbook.net
䯄婘婋麵滇婔婻冋床傯噸埩录傺婔婻蓖商臘㔗認婻蓖商儖赆䫘庯傯COMPANY 臘埻橬庹彖
testdb=# CREATE VIEW COMPANY_VIEW AS SELECT ID, NAME, AGE FROM COMPANY;gitbook.net
䯄婘埇傖婘䌂嚚䔇桹嚟婺昖臵垂鍙䔇臘昖臵COMPANY_VIEW㔗婋麵䔇冋床
testdb=# SELECT * FROM COMPANY_VIEW;www.gitbook.net
認儖库䫘傖婋䂷悩 gitbook.net
id | name | age ----+-------+----- 1 | Paul | 32 2 | Allen | 25 3 | Teddy | 23 4 | Mark | 25 5 | David | 27 6 | Kim | 22 7 | James | 24 (7 rows)gitbook.net
襕役鍴蓖商埻驔嘪䫘DROP VIEW臺埖婯VIEW_NAME㔗 DROP VIEW䔇嘺橸臺濘套婋
www.gitbook.net
testdb=# DROP VIEW view_name;www.gitbook.net
傖婋变傴儖役鍴COMPANY_VIEW gitbook.net
testdb=# DROP VIEW COMPANY_VIEW; www.gitbook.net