SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast Ciwan's Avatar
    Join Date
    May 2010
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation column definition order

    Hello Guys

    I am new here, so please go easy on me

    I am reading the book [ Build Your Own Database Driven Website Using PHP and MySQL 4th Edition ].

    I am now on Chapter 2 [ Introducing MySQL ] aaand I have a Question

    Does the order of this matter ?

    PHP Code:
    id INT NOT NULL AUTO_INCREMENT PRIMARY KEY 
    I mean can this also work ?

    PHP Code:
    id INT PRIMARY KEY AUTO_INCREMENT NOT NULL 
    I would greatly appreciate any help.

    Thank you.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,327
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what happened when you tested it?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast Ciwan's Avatar
    Join Date
    May 2010
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe I was scared to test it, I thought If I did > it will destroy all the work that I had done up to that point.

  4. #4
    SitePoint Enthusiast Ciwan's Avatar
    Join Date
    May 2010
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation

    OK I have now tested it and I get the following:

    Error 1064 (42000): 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 'NOT NULL AUTO_INCREMENT PRIMARY KEY INT, name TEXT, address TEXT) DEFAULT CHARAC' at line 2
    Does that mean It has a specific order that must be followed ?

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,327
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Ciwan View Post
    Does that mean It has a specific order that must be followed ?
    i don't think so, because it worked fine when i tested it
    Code:
    CREATE TABLE test_foo
    ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY 
    , foo VARCHAR(99)
    );
    
    CREATE TABLE test_bar
    ( id INT PRIMARY KEY AUTO_INCREMENT NOT NULL 
    , bar VARCHAR(99)
    );
    you might have something else in your CREATE TABLE statement that we can't see that's causing the error
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Enthusiast Ciwan's Avatar
    Join Date
    May 2010
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I think I have found the problem.

    I was doing this:

    PHP Code:
    id NOT NULL AUTO_INCREMENT INT PRIMARY KEY 
    But it seems that at least th Data Type MUST Follow the name of the field .. then the order of the others doesn't matter !! I say that because this worked:

    PHP Code:
    id INT AUTO_INCREMENT PRIMARY KEY NOT NULL 
    Am I right ?

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,327
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Ciwan View Post
    Am I right ?
    looks like it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    SitePoint Enthusiast Ciwan's Avatar
    Join Date
    May 2010
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Great !

    One thing cleared


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
  •