1
1
1010101010102014-03-21 12:09:11
MySQL
101010101010, 2014-03-21 12:09:11

How to fix error in SQL REFERENCES syntax?

CREATE TABLE org (
ogr_id INT not null primary key ,
identifier VARCHAR ( 25 ) not null UNIQUE
);
CREATE TABLE person (
p_id INT not null auto_increment primary key , 
p_name VARCHAR ( 25 ) not null ,
p_login VARCHAR ( 15 ) not null ,
password VARCHAR ( 15 ) not null , 
org INT not null ,
FOREIGN  KEY org REFERENCES org ( org_id )
ON UPDATE CASCADE 
ON DELETE CASCADE ,
UNIQUE (org_id, p_login , password ) 
)

such an error appears
Error code 1064, SQL state 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REFERENCES org ( org_id )
ON UPDATE CASCADE
ON DELETE CASCADE ,
UNIQUE (org_id,' at line 7

It's been over an hour and I can't figure out what's going on.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Morozov, 2014-03-21
@101010101010

First, you don't have org_id in this table, so UNIQUE (org_id) will throw an error.
Secondly,

CREATE TABLE person (
p_id INT not null auto_increment primary key , 
p_name VARCHAR ( 25 ) not null ,
p_login VARCHAR ( 15 ) not null ,
password VARCHAR ( 15 ) not null , 
org INT not null REFERENCES org ( org_id ) ON UPDATE CASCADE ON DELETE CASCADE ,
UNIQUE (org, p_login , password ) 
)

1
1001001 111, 2014-03-21
@IgorO2

syntax error =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question