3 Replies - 1585 Views - Last Post: 07 February 2007 - 07:16 AM

#1 ktsirig   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 14-September 05

weird syntax error

Posted 03 February 2007 - 10:15 AM

Hello all,
I am trying to create a table using the following syntax:

mysql_query ("CREATE TABLE IF NOT EXISTS RETURN (
RETURN_ID INT(12) NOT NULL AUTO_INCREMENT,
RETURN_RENTAL_ID INT(12) NOT NULL,
RETURN_COPY_ID INT(12) NOT NULL,
RETURN_MOVIE_ID INT(12) NOT NULL,
RETURN_DATE DATE NOT NULL,
PRIMARY KEY (RETURN_ID),
CONSTRAINT RETURN_IBFK_1 FOREIGN KEY(RETURN_RENTAL_ID) REFERENCES RENTAL(RENTAL_ID),
CONSTRAINT RETURN_IBFK_2 FOREIGN KEY(RETURN_COPY_ID) REFERENCES COPY(COPY_ID),
CONSTRAINT RETURN_IBFK_3 FOREIGN KEY(RETURN_MOVIE_ID) REFERENCES MOVIE(MOVIE_ID))"
) || die(mysql_error());

I get the following error:
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 'RETURN ( RETURN_ID INT(12) NOT NULL AUTO_INCREMENT, RETURN_RENTAL_ID I' at line 1


I am trying for 3 hours now to find what the problem is... I have checked everything, all about the foreign keys I use etc, but nothing seems to work... I can't see what my syntax error is...
Any help is greatly appreciated...

Is This A Good Question/Topic? 0
  • +

Replies To: weird syntax error

#2 wzeller   User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 85
  • Joined: 09-April 06

Re: weird syntax error

Posted 03 February 2007 - 11:32 PM

I may be missing something (I'll freely admit that a bunch of that code looks like it's over my head), but it appears that you aren't specifying a table name.

Could it be that easy?

Wayne
Was This Post Helpful? 0
  • +
  • -

#3 Trogdor   User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: weird syntax error

Posted 07 February 2007 - 03:45 AM

And is the IF NOT EXISTS RETURN something mysql specific, or spurious ?
Was This Post Helpful? 0
  • +
  • -

#4 Abbygail   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 13-July 06

Re: weird syntax error

Posted 07 February 2007 - 07:16 AM

I think RETURN is a mysql key word because this seems to work but if i change the RETURNED to RETURN it fails....
I'm running mysql 5.something on ubuntu 6.10... so there may be issues between different versions and systems.
You will have to validate it though.
Hope it helps.

CREATE TABLE IF NOT EXISTS RETURNED ( RETURN_ID INT(12) NOT NULL AUTO_INCREMENT, RETURN_RENTAL_ID INT(12) NOT NULL, RETURN_COPY_ID INT(12) NOT NULL, RETURN_MOVIE_ID INT(12) NOT NULL, RETURN_DATE DATE NOT NULL, PRIMARY KEY (RETURN_ID), CONSTRAINT RETURN_IBFK_1 FOREIGN KEY(RETURN_RENTAL_ID) REFERENCES RENTAL(RENTAL_ID), CONSTRAINT RETURN_IBFK_2 FOREIGN KEY(RETURN_COPY_ID) REFERENCES COPY(COPY_ID), CONSTRAINT RETURN_IBFK_3 FOREIGN KEY(RETURN_MOVIE_ID) REFERENCES MOVIE(MOVIE_ID));
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1