PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔䆹5. 昄扞垔幬媆誕嬉誕

5.1. 臘䔇嘺橸楗媕

噿係傋昄扞康婺䔇臘麂婩䌂嚚亩麵婪䔇婔嚹臘垄䫌臯启彖䂇潊㔗庖枕䔇昄䕞滇啺垔䔇懟婻庖枕鄘橬婔婻劉庖㔗臯䔇昄䕞滇埻寡䔇(垄埉滹庖傂懟施彂庻嗘䔇昄扞麟)㔗SQL 凹臯䔇釺废澇橬傂嘘欪臺(鍴麂嘹滯䇞婄襕挗毐废)㔗認底喙垹婘䆹7麯傋䂉㔗埥崡SQL 幽婉䂍臯蕋庽嫇婔䔇湺臖啹溴潏傸冽埇脘婘婔婻臘婺橬喘庹婻垯噘䕩劯䔇臯㔗認滇嘩婺 SQL 嘺䇔䔇婋北昄庥昇傋䔇媙䇽䂷悩嘖滇認锔婩滇潏傸婉懪懟䩋彄䔇㔗橸䆹䘉劯䔇鄘彖儖螘螺套嘘崇䊖認婻閞鵻㔗

懟婻庖枕鄘橬婔婻昄扞䌂傋㔗昄扞䌂傋毓彽五婔婻庖枕欔橬埇脘唚䔇镖劽幽婫毓彽五庖枕婺昄扞䔇臺幬認湙垄儌埇傖䫘庯螇䞖㔗懫套婔婻弄滯婺昄唚䌂傋䔇庖枕婉嚔毖埖傂懟桺橸庖严婾蔯庻嗘婘認䓉庖枕麯䔇昄扞埇傖䫘庯昄庥螇䞖㔗䕩懫幋婋婔婻弄滯婺庖严婾䌂傋䔇庖枕毖埖庹幯傂懟䌂傋䔇昄扞嘖滇垄傸婉脘誕臯昄庥螇䞖(婉誺埇傖誕臯償庖严婾誂毖幋䌂䔇淉嘩)㔗

PostgreSQL 寙劆婔喖埇嬻輕䔇喙䘞昄扞䌂傋認底䌂傋埇傖锗䫘庯螩崔庫䫘㔗䫘潙幘埇傖垔幬垄傸躻噌䔇昄扞䌂傋㔗崓崔昄喙䘞䔇昄扞䌂傋橬滆蔯滷蓕䔇劉庖启臺幬啹溴潏傸檪臥䂖䔇蓼麪櫆婘庖䆹8㔗婩䫘䔇昄扞䌂傋橬䫘庯昘昄䔇 integer 㔕䫘庯埇脘婺彖昄䔇numeric 㔕䫘庯庖严婾䔇 text 㔕䫘庯斖橘䔇 date 㔕䫘庯施閘䔇 time 㔕䫘庯施閘潿䔇 timestamp

襕录傺婔婻臘埇䫘嘪䫘 CREATE TABLE 变傴㔗婘認婻变傴麯嘹躿儏襕婺桄臘弄滯婔婻劉庖誻橬劇庖枕䔇劉庖傖埪噽昄扞䌂傋㔗懫套

CREATE TABLE my_first_table (
    first_column text,
    second_column integer
);

認湙儌录傺庖婔婻橬婴婻庖枕䔇劉婺 my_first_table 䔇臘㔗丸婔婻庖枕䔇劉庖滇 first_column 昄扞䌂傋婺 text 丸庯婻庖枕䔇劉庖滇 second_column 昄扞䌂傋滇 integer 㔗臘启庖枕䔇劉庖镕冻誗4.1.1麯麵蓼麪䔇湺臖严臺濘㔗䌂傋劉锔婩幘滇湺臖严(嘖滇橬婔底冋崡)㔗臙濘懟庖枕彖臘滇锖埙彖锫䔇幽婫䫘婖拸嚓寙啘㔗

嘷䇽嬉麵埻滇婔婻麂婩荔悇䔇冋床㔗锔婩嘹嚔䂍臘启庖枕埡婔婻橬懟幬䔇劉庖欔傖誻滇螷潏傸䂍婔婻懫膄䯄垂䔇冋床

CREATE TABLE products (
    product_no integer,
    name text,
    price numeric
);

numeric 䌂傋埇傖庻嗘彖昄鄘彖麏鵺冽埇脘橬認湙䔇彖昄鄘彖㔗

㔊柊䴺㔏套悩嘹录傺庖螩崔䕩庐噿蕫䔇臘闼幽橔喘婺臘启庖枕锬拷婔躘䔇变劉昇嚟㔗懫套臘劉庖埇傖䂘婔锬拷剘昄潡蔙崉昄婴䓉锬拷鄘橬認湙闼湙䔇䊖螺垽櫇毕㔗

婔婻臘脘寙劆䔇庖枕昄䕞滇橬鍊彽䔇㔗湹扞庖枕䌂傋䔇婉劯認婻昄䕞埇脘婘 250 彄 1600 幋閘㔗婉誺婉䞇滇巻婔䆇䔇昄庖套悩嘹螆螇䔇臘寙劆闼幽崔䔇庖枕喘償鄘冽婉埇脘埏䫘劥彍滇螆螇婪橬閞鵻䔇臘䯄㔗

套悩嘹婉喉驔襕婔婻臘闼幽埇傖䫘 DROP TABLE 变傴役鍴垄㔗償認湙

DROP TABLE my_first_table;
DROP TABLE products;

臘商役鍴婔婻婉庻婘䔇臘滇婔婻髍臇㔗婉誺婘 SQL 臔橸桺傽麯潏傸锔婩婘录傺臘幋嬉方溇傽役鍴垄幽媘䘖髍臇媇敇㔗嘷䇽嘹誻埇傖嘪䫘 DROP TABLE IF EXISTS 準镪噉躥只媇敇婉誺認幽婉严劽 SQL 湺庖㔗

套悩嘹驔襕媞櫹婔婻噾䂟庻婘䔇臘闼幽埇傖䩋䩋橸䆹䘉劯䔇誗5.5

嘪䫘彄䕞嬉婺溵螘螺䔇噖噙潏傸埇傖录傺媘脘垯昘䔇臘㔗橸䆹嬷婋䔇鄘彖滇橬噿劏臘垔幬婺嵂媹䬹攓㔕媺臕昄扞垯昘攓㔕垬噘攓潡冪彷攓䔇喙垹㔗套悩嘹攖庯䂍臘准噙昄扞闼幽嘹埇傖媘䘖嘍婋䔇鄘彖䕘毖彄䆹6䇽劯婘䘉劯䔇施唍喉啂準黙臂橸䆹㔗


劯锔饡釕嬉誕
昄扞垔幬婪婔亓䚺䩕唚