䯄婘嘉䘞饡釕 > 昄扞康 > PostgreSQL > PostgreSQL录傺臘

PostgreSQL录傺臘

準溊䪂臏昘䊖    䫌 悕垵幥 敘桄䬽橸    敟蓽庺渇

PostgreSQL䔇CREATE TABLE臺埖滇䫘準婘傂嘘毺垔䔇䔇昄扞康婺录傺婔婻桄臘㔗 gitbook.net

臺濘

CREATE TABLE臺埖䔇嘺橸臺濘套婋 gitbook.net

CREATE TABLE table_name(
   column1 datatype,
   column2 datatype,
   column3 datatype,
   .....
   columnN datatype,
   PRIMARY KEY( one or more columns )
); www.gitbook.net 

CREATE TABLE滇只臬昄扞康係䂘噿髞庖录傺婔婻桄䔇臘㔗䋸䬹䔇劉䓄潡湺臖套婋臘CREATE TABLE臺埖㔗嘷嬉昄扞康婺䔇臘橔彺滇䷺䔇幽婫儖欔拖橬䔇䫘潙埏庺䔇变傴㔗

www.gitbook.net

䇽劯婘拸埙喙準垔幬懟婔彖䔇彖臘婘臘婺滇傔幽湙䔇昄扞䌂傋㔗噽臺濘埻冖敘橙捄婋麵䔇冋床㔗

gitbook.net

垂冋

婋麵滇婔婻冋床垄录傺庖婔婻噸埩ID嘩婺婂髞䔇臘启NOT NULL䔇亥溘滆䴺認底庖枕婉脘婺NULL劯施录傺臖臘䔇螄嘘 www.gitbook.net

CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
); 

gitbook.net

螷潏傸录傺婔婻臘婘锟劯䔇䆹誗婺潏傸儖婘䂄幹婺嘪䫘

gitbook.net

CREATE TABLE DEPARTMENT(
   ID INT PRIMARY KEY      NOT NULL,
   DEPT           CHAR(50) NOT NULL,
   EMP_ID         INT      NOT NULL
); www.gitbook.net 

埇傖黯臕噾潊媘录傺嘪䫘\d变傴儖䫘庯彖庺庖鍇媹䔇昄扞康婺䔇欔橬臘㔗 www.gitbook.net

testdb-# \d 

www.gitbook.net

傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩

www.gitbook.net

           List of relations
 Schema |    Name    | Type  |  Owner
--------+------------+-------+----------
 public | company    | table | postgres
 public | department | table | postgres
(2 rows)
 gitbook.net 

嘪䫘\d臘劉準柟誄懟婻臘套婋欔䴺 gitbook.net

testdb-# \d company 

www.gitbook.net

傖婪PostgreSQL䔇臘嚔库䫘傖婋䂷悩

gitbook.net

        Table "public.company"
  Column   |     Type      | Modifiers
-----------+---------------+-----------
 id        | integer       | not null
 name      | text          | not null
 age       | integer       | not null
 address   | character(50) |
 salary    | real          |
 join_date | date          |
Indexes:
    "company_pkey" PRIMARY KEY, btree (id) gitbook.net 
橸䆍桺䆹鍴濘滯蘸蘘崡庺婺橸䆍寘录潡䚡臏
渵誯傂嘘嘵嚟䔇蘸蘘嘖臙媇媙濘滯庺崇優麉傡庺媿媘嚹携庥幹嘺䇔昍䘋
蘸蘘臙濘滯桺䆹蘸蘘躻悕垵幥 [http://www.gitbook.net]
橸桺湺鵻PostgreSQL录傺臘
蘸蘘臙媺䘍寘桺鷆毖:http://www.gitbook.net/html/postgresql/2013/080439.html
婪婔䇺PostgreSQL役鍴昄扞康      婋婔䇺PostgreSQL役鍴臘