+ Reply to Thread
Results 1 to 7 of 7

Thread: MySQL Format

  1. #1
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    MySQL Format

    Why does this query fail?
    Code:
    CREATE TABLE Order_Items (
    Order_ID CHAR(72) NOT NULL FOREIGN KEY REFERENCES Orders(ID),
    Product_ID INT(10) UNSIGNED NOT NULL FOREIGN KEY REFERENCES Items(ID),
    Quantity INT(10) UNSIGNED NOT NULL,
    Notes VARCHAR(255)
    );
    I know that the 'correct' form is with the constraints defined separately,
    Code:
    CREATE TABLE Order_Items (
    Order_ID CHAR(72) NOT NULL,
    Product_ID INT(10) UNSIGNED NOT NULL,
    Quantity INT(10) UNSIGNED NOT NULL,
    Notes VARCHAR(255),
    FOREIGN KEY (Order_ID) REFERENCES Orders(ID),
    FOREIGN KEY (Product_ID) REFERENCES Items(ID)
    );
    but why then can you define primary keys in the column definition? I prefer the SQL / Oracle / Microsoft SQL syntax, and hope to be able to use it with little changes to MySQL.

  2. #2
    blobtech is offline x10Hosting Member blobtech is an unknown quantity at this point
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    16

    Re: MySQL Format

    You are probably using the default MyISAM engine, which does not support foreign keys.
    Both tables should be of type InnoDB.

    Use the code:

    Code:
    CREATE TABLE `...` ( ... ) ENGINE = INNODB;
    Or

    Code:
    ALTER TABLE `...` ENGINE = INNODB;
    Please note that you could replace the ENGINE keyword with TYPE, they are aliases.
    Last edited by blobtech; 07-01-2009 at 06:11 AM.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: MySQL Format

    For MyISAM tables, MySQL ignores FOREIGN KEY constraints rather than considering them errors. The real cause is that MySQL just doesn't support that syntax, which is an extension to the SQL standard. Why didn't the MySQL developers add support for both? I'm not sure, but it's probably because there were more important tasks (additional functionality, bug fixes, performance) than adding a little syntactic sugar.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: MySQL Format

    I like the way you worded that misson :P

    However, thanks for the info about table types, I lost my database design notes a little while ago and neglected to include table type definitions. MySQL seems to have a vastly different syntax than the SQL standard, and that bothers me. Hopefully now that I stopped using w3schools.com, I won't be getting anymore misinformation about it.

  5. #5
    nirajkum is offline x10 Sophmore nirajkum is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    161

    Re: MySQL Format

    mysql is light weighted database ... so that expect complicated things from them

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: MySQL Format

    Quote Originally Posted by Twinkie View Post
    I lost my database design notes a little while ago and neglected to include table type definitions.
    Have you heard the good news? The words are SHOW CREATE TABLE, and they show Bob's love for you.

    Quote Originally Posted by Twinkie View Post
    MySQL seems to have a vastly different syntax than the SQL standard, and that bothers me. Hopefully now that I stopped using w3schools.com, I won't be getting anymore misinformation about it.
    Not so different from the standard, which every DBMS deviates from noticeably. For MySQL, I always head over to the MySQL reference manual.
    Last edited by misson; 07-02-2009 at 12:48 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  7. #7
    xav0989's Avatar
    xav0989 is offline Community Public Relation xav0989 is just really nice
    Join Date
    Jul 2008
    Location
    ifk
    Posts
    4,438

    Re: MySQL Format

    DBMS engines respect SQL standards less than browsers respect WWW standards.
    Xavier L | Community Public Relations Manager (Free Hosting Support)
    █ Yes, my position is too cool to even exist!
    How am I helping? Rate this post by clicking the icon below! (this is even better than "liking" a post)
    Terms of Service | Acceptable Use Policy | x10Hosting Wiki

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  3. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  4. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers