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

CREATE SCHEMA

劉䓄

CREATE SCHEMA -- 垔幬婔婻桄昇嚟

臺濘

CREATE SCHEMA schemaname [ AUTHORIZATION username ] [ schema_element [ ... ] ]
CREATE SCHEMA AUTHORIZATION username [ schema_element [ ... ] ]

柟誄

CREATE SCHEMA 婘嘷嬉昄扞康麯膷噖婔婻桄昇嚟㔗臖昇嚟劉儖婘嘷嬉昄扞康麯䯄庻䔇欔橬昇嚟劉婺嫇婔㔗

昇嚟垂鍙婪滇婔婻劉庖䷺閘垄寙劆变劉凹茇(臘㔕昄扞䌂傋㔕庘昄㔕淉嘩严)認底劉庖埇傖启噽垄昇嚟麯庻婘䔇噽垄凹茇麉劉㔗变劉凹茇襕幽滇锔誺䫘昇嚟劉嘩婺嬉䚔"媞閄"誕臯螪閞襕幽滇锔誺螆䘞婔婻抩䘵虇冇寙劆欔驔襕䔇昇嚟㔗婔溇婥五方媞閄凹茇劉䔇 CREATE 变傴鄘滇婘嘷嬉昇嚟婺录傺䔇(婘抩䘵虇冇橔嬉麵䔇昇嚟埇傖䫘 current_schema 庘昄準彴桺)㔗

埥崡CREATE SCHEMA 埇傖寙拸婘桄昇嚟婺录傺凹茇䔇床变傴㔗認底床变傴启闼底婘录傺垯昇嚟劯埏庺䔇变傴澇橬傂嘘寺彆埻婉誺滇套悩嘪䫘庖 AUTHORIZATION 床埖闼幽欔橬录傺䔇凹茇鄘儖赆臖䫘潙拖橬㔗

埗昄

schemaname

襕录傺䔇昇嚟劉庖㔗套悩䩕䘖彍嘪䫘䫘潙劉嘩婺昇嚟劉㔗認婻劉庖婉脘傖 pg_ 嚔崘啹婺認湙䔇劉庖媺䘍䂍係䂘昇嚟嘪䫘㔗

username

儖拖橬臖昇嚟䔇䫘潙劉㔗套悩䩕䘖䚺䩕婺欓臯臖变傴䔇䫘潙劉㔗埻橬轙亓䫘潙欉脘录傺婉匂庯躻噌䔇昇嚟㔗

schema_element

婔婻 SQL 臺埖垔幬婔婻襕婘昇嚟麯录傺䔇凹茇㔗䕞嬉埻橬 CREATE TABLE, CREATE VIEW, CREATE INDEX, CREATE SEQUENCE, CREATE TRIGGER, GRANT 滇埇傖毖埖䔇床埖㔗噽垄䌂傋䔇凹茇埇傖婘录傺垯昇嚟幋劯䔇䋸䆋变傴麯录傺㔗

濘懟

襕录傺昇嚟脄䫘臖变傴䔇䫘潙媙驔婘嘷嬉昄扞康婪橬 CREATE 溄鍊㔗嘷䇽轙亓䫘潙埇傖䂘嚔認婻演昖㔗

冋床

录傺婔婻昇嚟

CREATE SCHEMA myschema;

婺䫘潙 joe 录傺昇嚟昇嚟劉幘埆 joe

CREATE SCHEMA AUTHORIZATION joe;

录傺婔婻昇嚟幽婫婘麯麵录傺婔婻臘

CREATE SCHEMA hollywood
    CREATE TABLE films (title text, release date, awards text[])
    CREATE VIEW winners AS
        SELECT title, release FROM films WHERE awards IS NOT NULL;

臙濘懟婪麵䋸䆋䔇床变傴婉滇䫌彖埙䂷儆䔇㔗

婋麵䔇变傴滇垂䯄劯湙䂷悩䔇京昽臺埖

CREATE SCHEMA hollywood;
CREATE TABLE hollywood.films (title text, release date, awards text[]);
CREATE VIEW hollywood.winners AS
    SELECT title, release FROM hollywood.films WHERE awards IS NOT NULL;

噚垹攓

SQL 湺庖噕螩婘 CREATE SCHEMA 麯麵橬婔婻 DEFAULT CHARACTER SET 床埖傖埪懫䕞嬉 PostgreSQL 埇傖毖埖䔇敘崔䔇床变傴㔗

SQL 湺庖弄滯婘 CREATE SCHEMA 麯䔇床变傴埇傖傖傂懟釺废庺䯄㔗䕞嬉 PostgreSQL 麯䔇垂䯄誻婉脘崇䊖欔橬床变傴麯驔襕柊嬉嚘䫘䔇愙喕橬施唍埇脘驔襕麉毐婔婋床变傴䔇釺废傖镪噉嬉劏嚘䫘㔗

婘 SQL 湺庖麯昇嚟䔇欔橬蔙攂滇拖橬噽婺䔇欔橬凹茇㔗PostgreSQL 噕螩昇嚟寙劆麂昇嚟欔橬蔙欔橬䔇凹茇㔗埻橬婘昇嚟欔橬蔙 CREATE 庖躻噌䔇昇嚟䔇溄鍊䂍庖噽傡庺欉埇脘庺䯄㔗

埽蓕

ALTER SCHEMA, DROP SCHEMA

劯锔饡釕嬉誕
CREATE RULE婪婔亓CREATE SEQUENCE