Page 1 of 1
[SOLVED] statement - can anyone see anything wrong with this
Posted: Wed Feb 16, 2005 7:20 am
by mohson
can anyone see anything wrong with the statement:
Code: Select all
ALTER TABLE organisations ADD org_id PRIMARY KEY AUTO_INCREMENT;
I keep getting an error at line one
I keep getting ERROR 1064 you have an error in your SQL syntax near 'PRIMARY KEY AUTO_INCREMENT' at line one??
Why should this happen this looks a perfectly good statement to me CAN ANYONE PLEASE HELP???
Posted: Wed Feb 16, 2005 7:31 am
by Chris Corbyn
Try this
Code: Select all
ALTER TABLE organisations ADD `org_id` PRIMARY KEY (`org_id`) AUTO_INCREMENT
Posted: Wed Feb 16, 2005 7:31 am
by n00b Saibot
you cannot set "PRIMARY KEY" option on same phrase as of column name.
Change the query to this
Code: Select all
ALTER TABLE organisations ADD org_id AUTO_INCREMENT NOT NULL,
ADD PRIMARY KEY (org_id);
EDIT: I added NOT NULL because primary key can't be null
Posted: Wed Feb 16, 2005 7:33 am
by Chris Corbyn
Ha ha .... beaten by a minute again

Does it make a differecne if you put AUTO INCREMENT and PRIMARY KEY the other way around?
Posted: Wed Feb 16, 2005 7:38 am
by n00b Saibot
d11wtq wrote:Ha ha .... beaten by a minute again
I dunno why it is always so
d11wtq wrote:
Does it make a differecne if you put AUTO INCREMENT and PRIMARY KEY the other way around?
I think it does
Posted: Wed Feb 16, 2005 7:45 am
by mohson
I thought that would be it but again its saying error 1064 please help with this why is it not working???
Posted: Wed Feb 16, 2005 11:05 am
by mohson
No worries - SOLVED!!!