Doug Posted June 5, 2012 Share Posted June 5, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/ Share on other sites More sharing options...
Illusion Posted June 5, 2012 Share Posted June 5, 2012 First thing you are missing is user_id column data type and if table doesn't have a key defined.. auto increment column should be part of key. Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1351481 Share on other sites More sharing options...
Doug Posted June 6, 2012 Author Share Posted June 6, 2012 maybe it's harder than I thought. Is it possible? Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1351720 Share on other sites More sharing options...
Pikachu2000 Posted June 6, 2012 Share Posted June 6, 2012 What errors are returned by mysql_error? Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1351722 Share on other sites More sharing options...
Doug Posted June 6, 2012 Author Share Posted June 6, 2012 I get: Error 1064 (42000) you have an error in your SQL sytnax; check teh manual that corresposnd to your MySQL server version for the right syntax near user_id int auto_increment=16 Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1351727 Share on other sites More sharing options...
attaboy Posted June 7, 2012 Share Posted June 7, 2012 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'); Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1351944 Share on other sites More sharing options...
Doug Posted June 7, 2012 Author Share Posted June 7, 2012 Thanks but I was hoping to do it once the numbers are already there. So I have auto_increment 1,2,3,4 etc. I would like to change 1,2,3,4 to 10, 20, 30, and 40. Is this possible without manually changing each one? I'm sure it must be Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1351954 Share on other sites More sharing options...
fenway Posted June 16, 2012 Share Posted June 16, 2012 First, you can change the auto-increment starting value. Second, you really don't need to change UIDs -- ever. Quote Link to comment https://forums.phpfreaks.com/topic/263724-easy-question/#findComment-1354458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.