Jump to content

Recommended Posts

I should know this and can't believe it is not anywhere to be seen on Google

 

I would like to know how how to add a column (user_id) to an existing table that auto increments from 16 (rather than 1)

 

I have

 

alter table table name add column user_id not null auto_increment = 16

 

but this doesn't work

 

Help appreciated

 

Doug

 

Link to comment
https://forums.phpfreaks.com/topic/263724-easy-question/
Share on other sites

As far as I know you can't create a table row that includes a value.

This is what I did

first I created this table named test

then I entered

ALTER TABLE test ADD user_id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT;

I first tried without specifying PRIMARY KEY but I got an error telling me that auto_increment had to be a KEY

Then I inserted my first row of data and explicitly set a value for user_id of 16

INSERT INTO test values('Jim', 61, 'bum', 16);

I did a SELECT * FROM test;  to see if the value of user_id was 16 and it was

then I inserted another row to see if it would auto_increment from there and it did.

INSERT INTO test (name, age, job) VALUES ('Tom', 33, 'driver');

post-98811-13482403585394_thumb.png

post-98811-13482403585617_thumb.png

post-98811-13482403585832_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1351944
Share on other sites

  • 2 weeks later...
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.