Jump to content

Recommended Posts

I can't work out the syntax of how to do this:

 

I need to alter an existing table.  I need to add an int column, and have it auto-increment it.

 

alter table tablename add column ID  int(5);

 

how do i make it autoincrement?

 

//EDIT

Is this right?

 

alter table tablename add column ID MEDIUMINT NOT NULL AUTO_INCREMENT;

Link to comment
https://forums.phpfreaks.com/topic/74801-solved-alter-table/
Share on other sites

That didn't work neither did this:

 

alter table rdqout add column id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id);

 

You can't seem to set a field to AUTO_INCREMENT unless it's a KEY, and you can't set the KEY unless it's AUTO_INCREMENT...

 

Is this a limitation of MySQL?

 

I am dynamically creating the table, and need to add the ID field so i can do further manipulations.

Link to comment
https://forums.phpfreaks.com/topic/74801-solved-alter-table/#findComment-378245
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.