在 postgreSQL 中创建表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9826833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
create table in postgreSQL
提问by A.H.
I do not understand what is wrong with this query? Query tool does not want to create a table in PostgreSQL.
我不明白这个查询有什么问题?查询工具不想在 PostgreSQL 中创建表。
CREATE TABLE article (
article_id bigint(20) NOT NULL auto_increment,
article_name varchar(20) NOT NULL,
article_desc text NOT NULL,
date_added datetime default NULL,
PRIMARY KEY (article_id)
);
回答by A.H.
First the bigint(20) not null auto_increment
will not work, simply use bigserial primary key
. Then datetime
is timestamp
in PostgreSQL. All in all:
首先bigint(20) not null auto_increment
不起作用,只需使用bigserial primary key
. 然后datetime
是timestamp
在 PostgreSQL 中。总而言之:
CREATE TABLE article (
article_id bigserial primary key,
article_name varchar(20) NOT NULL,
article_desc text NOT NULL,
date_added timestamp default NULL
);
回答by kn3l
-- Table: "user"
-- DROP TABLE "user";
CREATE TABLE "user"
(
id bigserial NOT NULL,
name text NOT NULL,
email character varying(20) NOT NULL,
password text NOT NULL,
CONSTRAINT user_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE "user"
OWNER TO postgres;
回答by sega_sai
Replace bigint(20) not null auto_increment
by bigserial not null
and
datetime
by timestamp
更换bigint(20) not null auto_increment
由bigserial not null
并且
datetime
通过timestamp
回答by skay
Please try this:
请试试这个:
CREATE TABLE article (
article_id bigint(20) NOT NULL serial,
article_name varchar(20) NOT NULL,
article_desc text NOT NULL,
date_added datetime default NULL,
PRIMARY KEY (article_id)
);