䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL躻媘嵂媹

PostgreSQL躻媘嵂媹

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

PostgreSQL拖橬䔇昄扞䌂傋smallserialserial 启bigserial認底鄘婉滇䩘溼䔇䌂傋嘖備備滇婔婻楗媕婪䔇冪彷婺录傺嫇婔湺臖严彖㔗認底鄘滇䕩嚚彄櫇毕AUTO_INCREMENT匂攓噽傡婔底昄扞康㔗 www.gitbook.net

套悩愿橬婔婻婾臯彖䔇嫇婔亥溘潡婂髞垄䯄婘媙釂赆毺垔儌償噽傡昄扞䌂傋㔗

gitbook.net

䌂傋劉䓄废彖录傺昘昄彖㔗䌂傋劉䓄BIGSERIAL录傺婔婻bigint彖㔗BIGSERIAL庫嘪䫘套悩鵇螇轙誺231湺臖严嘪䫘䔇昘婻䫘变变橘臘㔗臖䔇䌂傋劉䓄smallserial录傺婔婻SMALLINT彖㔗

www.gitbook.net

臺濘:

婾臯昄扞䌂傋䔇嘺橸䫘濘套婋 www.gitbook.net

CREATE TABLE tablename (
colname SERIAL
); 

gitbook.net

垂冋:

蔄荏襕录傺䔇COMPANY臘套婋 www.gitbook.net

testdb=# CREATE TABLE COMPANY(
   ID  SERIAL PRIMARY KEY,
   NAME           TEXT      NOT NULL,
   AGE            INT       NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
); 
gitbook.net

䯄婘某噖婋麵䔇螄嘘臘COMPANY www.gitbook.net

INSERT INTO COMPANY (NAME,AGE,ADDRESS,SALARY)
VALUES ( 'Paul', 32, 'California', 20000.00 );

INSERT INTO COMPANY (NAME,AGE,ADDRESS,SALARY)
VALUES ('Allen', 25, 'Texas', 15000.00 );

INSERT INTO COMPANY (NAME,AGE,ADDRESS,SALARY)
VALUES ('Teddy', 23, 'Norway', 20000.00 );

INSERT INTO COMPANY (NAME,AGE,ADDRESS,SALARY)
VALUES ( 'Mark', 25, 'Rich-Mond ', 65000.00 );

INSERT INTO COMPANY (NAME,AGE,ADDRESS,SALARY)
VALUES ( 'David', 27, 'Texas', 85000.00 );


INSERT INTO COMPANY (NAME,AGE,ADDRESS,SALARY)
VALUES ( 'Kim', 22, 'South-Hall', 45000.00 );

INSERT INTO COMPANY (NAME,AGE,ADDRESS,SALARY)
VALUES ( 'James', 24, 'Houston', 10000.00 ); 
www.gitbook.net

認儖某噖彄臘COMPANY 䔇7噄䂇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 
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL躻媘嵂媹
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080781.html
婪婔䇺PostgreSQL床昖臵      婋婔䇺PostgreSQL溄鍊