[SOLVED] statement - can anyone see anything wrong with this

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

[SOLVED] statement - can anyone see anything wrong with this

Post 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???
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Try this

Code: Select all

ALTER TABLE organisations ADD `org_id` PRIMARY KEY (`org_id`) AUTO_INCREMENT
Last edited by Chris Corbyn on Wed Feb 16, 2005 7:31 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

you cannot set "PRIMARY KEY" option on same phrase as of column name.
Change the query to this :arrow:

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
Last edited by n00b Saibot on Wed Feb 16, 2005 7:34 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

d11wtq wrote:Ha ha .... beaten by a minute again
I dunno why it is always so :( :lol:
d11wtq wrote: Does it make a differecne if you put AUTO INCREMENT and PRIMARY KEY the other way around?
I think it does
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

I thought that would be it but again its saying error 1064 please help with this why is it not working???
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

No worries - SOLVED!!!
Post Reply