䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL蓖商

PostgreSQL蓖商

準溊寘录桺䆹    䫌 悕垵幥 敘桄䬽橸    敟蓽庺渇

蓖商滇嚻臘㔗幘儌滇臘傡傸滇婉滇䩘溼䔇臘嘖傉䇽滆䴺婺捞锔臘準䔇SELECT㔗婔婻蓖商埇傖傼臘婔婻䩘溼䔇臘䔇婔婻床镖傯婔婻捞锔䔇臘婺锬拷䬹垔䔇彖潡昊底臯㔗蓖商䫔躿埇傖傼臘媹噖臘㔗啹婺蓖商赆彖陉剘䋸䔇溄鍊嘹埇傖嘪䫘垄傸準鍊彽凹臘䔇螪閞嘪䫘潙埻䩋彄䬹垔䔇臯潡彖婔婻臘㔗 www.gitbook.net

傯婔婻潡崔婻臘蓖商埇傖寙劆婔婻臘䔇欔橬臯潡锬垔臯㔗埇傖傯婔婻潡崔婻臘認埡喿庯喍噖PostgreSQL昖臵录傺婔婻蓖商录傺蓖商㔗 gitbook.net

蓖商滇婔䓉荔臘螷䫘潙啔彄傖婋庹䗹 gitbook.net

  • 䂷悇昄扞䔇桹嚟䫘潙潡䌂彆䔇䫘潙埏䯄躻䇽潡䕘蓗㔗 gitbook.net

  • 鍊彽螪閞䫘潙埻脘䩋彄橬鍊䔇昄扞蔯婉滇垯昘䔇臘京昄扞㔗 gitbook.net

  • 攂䂷劇䓉臘婺䔇昄扞埇䫘庯䫘潊檖只㔗

    gitbook.net

䫌庯蓖商婉劯庯捞锔䔇臘欔傖埇脘婉脘欓臯DELETEINSERT潡UPDATE臺埖婘蓖商婪㔗嘖滇旘埇傖录傺蓇彍敘溼溴閞鵻嘪䫘DELETEINSERT潡UPDATE蓖商婪㔗 www.gitbook.net

录傺蓖商:

PostgreSQL䔇嘪䫘CREATE VIEW臺埖录傺蓖商㔗傯剘婔臘㔕崔婻臘潡埥婔婻蓖商婺埇傖录傺PostgreSQL蓖商㔗 www.gitbook.net

CREATE VIEW臺濘䔇嘺橸愙喕套婋

gitbook.net

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 臘婺橬傖婋螄嘘

www.gitbook.net

 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    |  10000
 
www.gitbook.net

䯄婘婋麵滇婔婻冋床傯噸埩录傺婔婻蓖商臘㔗認婻蓖商儖赆䫘庯傯COMPANY 臘埻橬庹彖

www.gitbook.net

testdb=# CREATE VIEW COMPANY_VIEW AS
SELECT ID, NAME, AGE
FROM  COMPANY; 

gitbook.net

䯄婘埇傖婘䌂嚚䔇桹嚟婺昖臵垂鍙䔇臘昖臵COMPANY_VIEW㔗婋麵䔇冋床

gitbook.net

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 
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL蓖商
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080777.html
婪婔䇺PostgreSQL TRUNCATE TABLE变傴      婋婔䇺PostgreSQL庋媇