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

5.2. 䚺䩕唚

婔婻庖枕埇傖蕋庽䚺䩕唚㔗套悩桄录傺庖婔婻昄扞臯蔯橬底庖枕䔇昄唚澇橬弄滯闼幽認底庖枕儖赆准噙婺垄傸劇躻䔇䚺䩕唚㔗婔溇昄扞媞櫹变傴幘埇傖滯䇞婄襕挗檪婔婻庖枕螆䘞婺垄䔇䚺䩕唚蔯婉䫘庋噽䘖長認婻䚺䩕唚滇傔幽㔗橬噿昄扞淉嘩䔇变傴婘䆹6

套悩澇橬滯䇞弄滯䚺䩕唚闼幽䚺䩕唚滇 NULL 㔗認幽啔锔婩滇劽䊖䔇啹婺 NULL 臘䴺"橻䘖"㔗

婘婔婻臘垔幬麯䚺䩕唚滇婘庖枕昄扞䌂傋劯麵彖庺䔇㔗懫套

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

䚺䩕唚埇傖滇婔婻臘膆嚟垄嚔婘某噖䚺䩕唚䔇施唍螇䞖(婉滇婘录傺臘䔇施唍)㔗婔婻婩蓕䔇冋床滇婔婻 timestamp 庖枕埇脘橬䚺䩕唚 now() 垄臘䴺某噖臯䔇施彂㔗埥崡婔婻婩蓕䔇冋床滇婺懟婔臯䫘潊婔婻"废彖埙"㔗婘 PostgreSQL 麯锔婩滇䫘䌂嚚婋麵認湙䔇桹濘䫘潊䔇

CREATE TABLE products (
    product_no integer DEFAULT nextval('products_product_no_seq'),
    ...
);

認麯䔇 nextval() 傯婔婻废彖凹茇(埗黙誗9.12)柊冕劯䂓䔇昄唚㔗認䓉啔濘麂婩捞镉傖躿庯潏傸橬婔婻婷閘䔇䚷喍䫘庯溴䕞䔇

CREATE TABLE products (
    product_no SERIAL,
    ...
);

SERIAL 䚷喍婘誗8.1.4麯橬誕婔準柟誄㔗


劯锔饡釕嬉誕
臘䔇嘺橸楗媕婪婔亓亥溘