SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)

    What is wrong with this create statement?

    I have the following query:

    Code:
     CREATE TABLE special(
    sp_p_id int( 5 ) NOT NULL ,
    sp_desc text NULL ,
    sp_rates set( 'true', 'false' ) NOT NULL DEFAULT 'true',
    sp_home set( 'true', 'false' ) NOT NULL DEFAULT 'false',
    FOREIGN KEY sp_p_id REFERENCES product( p_id ) ON DELETE CASCADE
    ) TYPE = InnoDB
    The 'product' table already exsists with the p_id field being the primary key. I get a 1064 error near 'REFERENCES product(p_id) ON DELETE CASCADE'. Anyone have an idea as to why I am getting this error?

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    700
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    FOREIGN KEY (sp_p_id) REFERENCES product( p_id ) ON DELETE CASCADE

  3. #3
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the above does not work make sure your MySQL version supports ON DELETE .. ,

  4. #4
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it was the () around sp_p_id... I caught it about 10 minutes after I made the post.

    Now I have to figure out how to implement foreign keys since my host doesn't support InnoDB


Bookmarks

Posting Permissions

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