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
mohson
Forum Contributor
Posts: 372 Joined: Thu Dec 02, 2004 6:58 am
Location: London
Post
by mohson » Wed Feb 16, 2005 7:20 am
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???
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Feb 16, 2005 7:31 am
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.
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Wed Feb 16, 2005 7:31 am
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
Last edited by
n00b Saibot on Wed Feb 16, 2005 7:34 am, edited 1 time in total.
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098 Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia
Post
by Chris Corbyn » Wed Feb 16, 2005 7:33 am
Ha ha .... beaten by a minute again
Does it make a differecne if you put AUTO INCREMENT and PRIMARY KEY the other way around?
n00b Saibot
DevNet Resident
Posts: 1452 Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:
Post
by n00b Saibot » Wed Feb 16, 2005 7:38 am
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
mohson
Forum Contributor
Posts: 372 Joined: Thu Dec 02, 2004 6:58 am
Location: London
Post
by mohson » Wed Feb 16, 2005 7:45 am
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 » Wed Feb 16, 2005 11:05 am
No worries - SOLVED!!!