ciwan — 2010-05-29T16:15:20-04:00 — #1
I am new here, so please go easy on me :shifty:
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 ?
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
I mean can this also work ?
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL
I would greatly appreciate any help.
r937 — 2010-05-30T14:53:41-04:00 — #2
looks like it
ciwan — 2010-05-30T15:55:11-04:00 — #3
One thing cleared
ciwan — 2010-05-30T11:03:04-04:00 — #4
Ok I think I have found the problem.
I was doing this:
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:
id INT AUTO_INCREMENT PRIMARY KEY NOT NULL
Am I right ?
r937 — 2010-05-29T18:53:11-04:00 — #5
what happened when you tested it?
r937 — 2010-05-29T21:20:40-04:00 — #6
i don't think so, because it worked fine when i tested it
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
ciwan — 2010-05-29T20:12:13-04:00 — #7
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 ? :injured:
ciwan — 2010-05-29T19:57:10-04:00 — #8
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.