user7732640
user7732640

Reputation:

sql error on key word "references"

I'd like you guy to help me please. Here's some SQL code I'm trying to execute.

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));

I get an error like "syntax error nearby 'references Personne(id_personne))' line 5.

I don't know where it's from. I went to W3school.com and from what I understand, what I wrote is correct. But it just doesn't work.

Any kind of help would be appreciated !

PS : I tried on MySql and Postgresql, same result.

Upvotes: 0

Views: 35

Answers (1)

sumit
sumit

Reputation: 15464

You forgot to put the column name

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)

Upvotes: 1

Related Questions