关键字“引用”上的SQL错误

问题描述 投票:0回答:1

我想请你帮我一个人。这是我正在尝试执行的一些SQL代码。

create table Personne (
id_personne serial primary key, 
nom text not null, 
prenom text not null, 
email text not null);

create table Ressource (
id_ressource serial primary key, 
nom_r text not null, 
url text not null,  
id_personne int not null, foreign key references Personne(id_personne));

我得到一个错误,如“附近的语法错误'引用Personne(id_personne))'第5行。

我不知道它来自哪里。我去了W3school.com,根据我的理解,我写的是正确的。但它只是不起作用。

任何形式的帮助将不胜感激!

PS:我试过MySql和Postgresql,结果相同。

mysql sql postgresql
1个回答
1
投票

你忘了把列名

create table Ressource (
id_ressource serial primary key, 
nom_r text not null, 
url text not null,  
id_personne int not null, 
foreign key(id_personne) references Personne(primary_key_from_personne));
            ^^^^^^^^^^^^^^^^ 
            (you missed it)
© www.soinside.com 2019 - 2024. All rights reserved.