Jump to content

Easy question!


Doug

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.