Results 1 to 8 of 8

Thread: SQL Syntax

  1. #1
    Join Date
    Jun 2007
    Location
    London
    Posts
    117

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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?

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    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)

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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

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

  6. #6
    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!

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

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •