我第一次使用PostgreSQL。我有这样的声明:
CREATE TABLE IF NOT EXISTS sequences (
SEQU_NK SERIAL PRIMARY KEY NOT NULL UNIQUE,
NOM_SEQU varchar(30) NOT NULL,
PROCHAIN bigint NOT NULL,
PRIMARY KEY (SEQU_NK),
UNIQUE KEY IDX_SEQU_NOM (NOM_SEQU)
)
当我跑步时,我得到:
ERROR: syntax error at or near "KEY" LINE 6: UNIQUE KEY IDX_SEQU_NOM (NOM_SEQU) ^ ********** Error ********** ERROR: syntax error at or near "KEY"
答案 0 :(得分:0)
试试这样:
CREATE TABLE IF NOT EXISTS sequences (
SEQU_NK SERIAL PRIMARY KEY NOT NULL UNIQUE,
NOM_SEQU varchar(30) NOT NULL,
PROCHAIN bigint NOT NULL,
CONSTRAINT "IDX_SEQU_NOM" UNIQUE (NOM_SEQU)
)
<强> SQLFIDDLE DEMO 强>
答案 1 :(得分:0)
CREATE TABLE sequences (
sequ_nk serial PRIMARY KEY,
nom_sequ varchar(30) NOT NULL UNIQUE,
prochain bigint NOT NULL
);
它是UNIQUE
,而不是
只能有一个 UNIQUE KEY
PRIMARY KEY
PRIMARY KEY
列自动为UNIQUE
和NOT NULL
Read the manual.
Or, better yet, read the manual for your actual Postgres version 8.4 - 告诉您版本8.4中尚未实现 (等待9.1)。IF NOT EXISTS
或者,更好的是,升级到Postgres的当前版本。 Version 8.4 has reached EOL last year.
旁白:不要使用带引号的大写标识符,或者必须始终引用它们。