Welcome to WebmasterWorld Guest from 54.205.20.160

Forum Moderators: open

Message Too Old, No Replies

weird syntax error.

   
5:04 pm on Feb 3, 2007 (gmt 0)

5+ Year Member



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...

5:39 pm on Feb 3, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



RETURN
is a reserved word [dev.mysql.com] in MySQL. You must surround it with the prime symbol to escape it! (`). An example:

...CREATE TABLE IF NOT EXISTS `RETURN`(...

Generally it is not encouraged to use names that are the same as a reserved word. You might want to think about changing the name of the table.

Good luck! :)