If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > SQL Syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-08, 16:19
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
SQL Syntax

Hello all,

Whats wrong with this? I am not great with sql but i used the following from eclipse where i modelled a database that i will create. i used a function which generated the sql for me:

Code:
DROP TABLE IF EXISTS  Group;
DROP TABLE IF EXISTS  Member;
DROP TABLE IF EXISTS  MemberGroupRel;

CREATE TABLE  MemberGroupRel (
       memberID MEDIUMINT NOT NULL
     , groupID MEDIUMINT NOT NULL
     , owner BOOLEAN NOT NULL
)TYPE=InnoDB;

CREATE TABLE Member (
       memberID MEDIUMINT NOT NULL AUTO_INCREMENT
     , userName VARCHAR(50) NOT NULL
     , password VARCHAR(24) NOT NULL
     , verified BOOLEAN
     , PRIMARY KEY (memberID)
     , INDEX ()
     , CONSTRAINT memberFK FOREIGN KEY ()
                  REFERENCES MemberGroupRel ()
)TYPE=InnoDB;

CREATE TABLE Group (
       groupID MEDIUMINT NOT NULL AUTO_INCREMENT
     , groupName VARCHAR(255) NOT NULL
     , timeCreated DATETIME NOT NULL
     , PRIMARY KEY (groupID)
     , INDEX ()
     , CONSTRAINT groupFK FOREIGN KEY ()
                  REFERENCES MemberGroupRel ()
)TYPE=InnoDB;
When i came to run this sql it said i had a syntax error!

Thanks for any help all
Reply With Quote
  #2 (permalink)  
Old 02-21-08, 20:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
dang it all, i just learned that the reason my Microsoft® CrystalBall© won't boot is because it's missing the latest vista patch

so could you, like, you know, give us a hint about which of the nine hundred and thirty-seven possible error messages you actually got?

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-22-08, 02:49
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
I think you need to list the columns inside the brackets, e.g:
Code:
CONSTRAINT memberFK FOREIGN KEY (memberID)
                  REFERENCES MemberGroupRel (memberID)
And I'm not sure what the INDEX() function should do (but then I'm not a MySQL Expert)
Reply With Quote
  #4 (permalink)  
Old 02-22-08, 02:56
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
I'd guess the eclipse modules isn't creating the indexes, or maybe it expects you to specify what indexes you are intending to use.

both the primary (Primary Key) & secondary (INDEX) index definitions are missing or incomplete
like wise the constraint clauses
Reply With Quote
  #5 (permalink)  
Old 02-22-08, 10:57
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
"#1064 - 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 'Group' at line 1"

Thats the error i got when i tried to run this in phpMyAdmin - i was using another generic database creator program.

MySQL client version: 5.0.37
Server version: 5.0.41-community-nt
Reply With Quote
  #6 (permalink)  
Old 02-22-08, 11:18
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Quote:
Originally Posted by shammat
I think you need to list the columns inside the brackets, e.g:
Code:
CONSTRAINT memberFK FOREIGN KEY (memberID)
                  REFERENCES MemberGroupRel (memberID)
And I'm not sure what the INDEX() function should do (but then I'm not a MySQL Expert)
Thank you very much!!! Your right!
Reply With Quote
  #7 (permalink)  
Old 02-25-08, 03:37
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
GROUP is a reserved word, so I recommend using backticks to enclose that table name if you want to use it. e.g. CREATE TABLE `Group` (...

Also, to the best of my knowledge, the TYPE indicator is deprecated now as of MySQL 5.0 (but you can still use it of course). You should be using ENGINE=InnoDB, for example.
Reply With Quote
  #8 (permalink)  
Old 02-25-08, 12:33
compsci compsci is offline
Registered User
 
Join Date: Jun 2007
Location: London
Posts: 117
Quote:
Originally Posted by aschk
GROUP is a reserved word, so I recommend using backticks to enclose that table name if you want to use it. e.g. CREATE TABLE `Group` (...

Also, to the best of my knowledge, the TYPE indicator is deprecated now as of MySQL 5.0 (but you can still use it of course). You should be using ENGINE=InnoDB, for example.
Yeh, i twigged after a while that it was reserved, now i have changed it.

I have noted the advice, the deprecated TYPE. Also i should do everything in MySQL 5.0 actualy.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On